async-job-adapter-active_job 0.7.2 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92468d5194031da303e154b420ca5230a173d143d4ac5d9f25b8371b84dd3321
4
- data.tar.gz: 8d348e952d404c310c9b19a13acf8d833c700dc75ec9024082c17876679903cf
3
+ metadata.gz: 9fc827732ecf5a8411767537e45e6dfe818ca807cd5a5bafadf258bbbccebe01
4
+ data.tar.gz: 295799259e5dd60f48b70203a6051386349e23248961a960526167b00ed5fb98
5
5
  SHA512:
6
- metadata.gz: 5d87aa59963f061bf6193651151dd40efea88976b02788845c6c23d9026055dc5f2b538808c333b9db4177d3c67eb52b6032097fb73621704aa4f35a235eb067
7
- data.tar.gz: 608558e01b4bd710e15413a39aa4d8f1628c03cb47d194e78448dc5b2a5234fd00c05a2fd4050abea9219e3f60f24b82391d19d1557269451c7dd771c3adb2b7
6
+ metadata.gz: dfc8bead67d201f1ead504441be4d313bafdbde78a7987501edbee194dabdc77feeaae02b34dc3a407c9c16509f26eea0c1e9d43a2495d42dae47d4e6f17364d
7
+ data.tar.gz: c3edbf51797ac06519dcb93cb1ba25ec351a85703b6e90c1632b77614c8ac1f5fb190954ce8e92fe54301b6c5aa65cc887f2f09783cb3f896a33d02a150ed3e0
checksums.yaml.gz.sig CHANGED
Binary file
@@ -14,30 +14,30 @@ module Async
14
14
  module Job
15
15
  module Adapter
16
16
  module ActiveJob
17
- # A dispatcher for managing multiple backends.
17
+ # A dispatcher for managing multiple definitions.
18
18
  class Dispatcher
19
- # Prepare the dispacher with the given backends and aliases.
20
- # @parameter backends [Hash(String, Proc)] The backends to use for processing jobs.
21
- # @parameter aliases [Hash(String, Proc)] The aliases for the backends.
22
- def initialize(backends, aliases = {})
23
- @backends = backends
19
+ # Prepare the dispacher with the given definitions and aliases.
20
+ # @parameter definitions [Hash(String, Proc)] The definitions to use constructing queues.
21
+ # @parameter aliases [Hash(String, Proc)] The aliases for the definitions.
22
+ def initialize(definitions, aliases = {})
23
+ @definitions = definitions
24
24
  @aliases = aliases
25
25
 
26
- @pipelines = {}
26
+ @queues = {}
27
27
  end
28
28
 
29
- # @attribute [Hash(String, Proc)] The backends to use for processing jobs.
30
- attr :backends
29
+ # @attribute [Hash(String, Proc)] The definitions to use for processing jobs.
30
+ attr :definitions
31
31
 
32
- # @attribute [Hash(String, String)] The aliases for the backends.
32
+ # @attribute [Hash(String, String)] The aliases for the definitions.
33
33
  attr :aliases
34
34
 
35
35
  # Lookup a pipeline by name, constructing it if necessary using the given backend.
36
36
  # @parameter name [String] The name of the pipeline/backend.
37
37
  def [](name)
38
- @pipelines.fetch(name) do
39
- backend = @backends.fetch(name)
40
- @pipelines[name] = build(backend)
38
+ @queues.fetch(name) do
39
+ definition = @definitions.fetch(name)
40
+ @queues[name] = build(definition)
41
41
  end
42
42
  end
43
43
 
@@ -45,30 +45,30 @@ module Async
45
45
  def enqueue(job)
46
46
  name = @aliases.fetch(job.queue_name, job.queue_name)
47
47
 
48
- self[name].producer.enqueue(job)
48
+ self[name].client.enqueue(job)
49
49
  end
50
50
 
51
51
  # Enqueue a job for processing at a specific time.
52
52
  def enqueue_at(job, timestamp)
53
53
  name = @aliases.fetch(job.queue_name, job.queue_name)
54
54
 
55
- self[name].producer.enqueue_at(job, timestamp)
55
+ self[name].client.enqueue_at(job, timestamp)
56
56
  end
57
57
 
58
58
  # Start processing jobs in the given pipeline.
59
59
  def start(name)
60
- self[name].consumer.start
60
+ self[name].server.start
61
61
  end
62
62
 
63
- private def build(backend)
63
+ private def build(definition)
64
64
  builder = Builder.new(Executor::DEFAULT)
65
65
 
66
- builder.instance_eval(&backend)
66
+ builder.instance_eval(&definition)
67
67
 
68
- builder.build do |producer|
69
- # Ensure that the producer is an interface:
70
- unless producer.is_a?(Interface)
71
- Interface.new(producer)
68
+ builder.build do |client|
69
+ # Ensure that the client is an interface:
70
+ unless client.is_a?(Interface)
71
+ Interface.new(client)
72
72
  end
73
73
  end
74
74
  end
@@ -23,6 +23,14 @@ module Async
23
23
  @delegate&.call(job)
24
24
  end
25
25
 
26
+ def start
27
+ @delegate&.start
28
+ end
29
+
30
+ def stop
31
+ @delegate&.stop
32
+ end
33
+
26
34
  # The default executor, at the end of the pipeline.
27
35
  DEFAULT = self.new.freeze
28
36
  end
@@ -4,7 +4,7 @@
4
4
  # Copyright, 2024, by Samuel Williams.
5
5
 
6
6
  require 'async/job'
7
- require 'async/job/backend/inline'
7
+ require 'async/job/processor/inline'
8
8
 
9
9
  require 'thread/local'
10
10
 
@@ -19,27 +19,27 @@ module Async
19
19
  # A Rails-specific adapter for `ActiveJob` that allows you to use `Async::Job` as the backend.
20
20
  class Railtie < ::Rails::Railtie
21
21
  # The default pipeline for processing jobs, using the `Inline` backend.
22
- DEFAULT_PIPELINE = proc do
23
- queue Backend::Inline
22
+ DEFAULT_QUEUE_DEFINITION = proc do
23
+ dequeue Processor::Inline
24
24
  end
25
25
 
26
26
  def initialize
27
- @backends = {"default" => DEFAULT_PIPELINE}
27
+ @definitions = {"default" => DEFAULT_QUEUE_DEFINITION}
28
28
  @aliases = {}
29
29
  end
30
30
 
31
- # The backends that are available for processing jobs.
32
- attr :backends
31
+ # The queues that are available for processing jobs.
32
+ attr :definitions
33
33
 
34
- # The aliases for the backends.
34
+ # The aliases for the definitions, if any.
35
35
  attr :aliases
36
36
 
37
37
  # Define a new backend for processing jobs.
38
38
  # @parameter name [String] The name of the backend.
39
39
  # @parameter aliases [Array(String)] The aliases for the backend.
40
40
  # @parameter block [Proc] The block that defines the backend.
41
- def backend_for(name, *aliases, &block)
42
- @backends[name] = block
41
+ def queue_for(name, *aliases, &block)
42
+ @definitions[name] = block
43
43
 
44
44
  if aliases.any?
45
45
  alias_for(name, *aliases)
@@ -55,14 +55,14 @@ module Async
55
55
 
56
56
  # Used for dispatching jobs to a thread-local backend to avoid thread-safety issues.
57
57
  class ThreadLocalDispatcher
58
- def initialize(backends, aliases)
59
- @backends = backends
58
+ def initialize(definitions, aliases)
59
+ @definitions = definitions
60
60
  @aliases = aliases
61
61
  end
62
62
 
63
63
  # The dispatcher for the current thread.
64
64
  def dispatcher
65
- Thread.current.async_job_adapter_active_job_dispatcher ||= Dispatcher.new(@backends)
65
+ Thread.current.async_job_adapter_active_job_dispatcher ||= Dispatcher.new(@definitions, @aliases)
66
66
  end
67
67
 
68
68
  # Enqueue a job to be processed at a specific time.
@@ -87,10 +87,11 @@ module Async
87
87
  config.active_job.queue_adapter.start(name)
88
88
  end
89
89
 
90
- DEFAULT_QUEUE_ADAPTER = ThreadLocalDispatcher.new(self.backends, self.aliases)
90
+ DEFAULT_DISPATCHER = ThreadLocalDispatcher.new(self.definitions, self.aliases)
91
91
 
92
92
  config.async_job = self
93
- config.active_job.queue_adapter = DEFAULT_QUEUE_ADAPTER
93
+
94
+ config.active_job.queue_adapter = DEFAULT_DISPATCHER
94
95
  end
95
96
  end
96
97
  end
@@ -7,7 +7,7 @@ module Async
7
7
  module Job
8
8
  module Adapter
9
9
  module ActiveJob
10
- VERSION = "0.7.2"
10
+ VERSION = "0.9.0"
11
11
  end
12
12
  end
13
13
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-job-adapter-active_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -37,7 +37,7 @@ cert_chain:
37
37
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
38
38
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
39
39
  -----END CERTIFICATE-----
40
- date: 2024-08-02 00:00:00.000000000 Z
40
+ date: 2024-08-08 00:00:00.000000000 Z
41
41
  dependencies:
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: async-job
@@ -45,14 +45,14 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '0.5'
48
+ version: '0.9'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '0.5'
55
+ version: '0.9'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: async-service
58
58
  requirement: !ruby/object:Gem::Requirement
metadata.gz.sig CHANGED
Binary file