async-job-adapter-active_job 0.6.0 → 0.7.1

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: 37290d3cfe5fd027791f3789dd53094e0ce4cbb5923933072dd2d1b3a01f806a
4
- data.tar.gz: 7365c94254728a5be3e8c3215338f6afccd189a837349cda3835c221d42c417f
3
+ metadata.gz: 0bff5e1735d3c2416786dae8b49a40d165f0154ec77d84ecec129d5d7f19406c
4
+ data.tar.gz: c91e5b6a631570caa9a6bb2b27cfce1a2d5741baf0f980979e644bdcc06affea
5
5
  SHA512:
6
- metadata.gz: 518dd58363f88565bc7ce20625bdd3b851012af3b92b772eb236630669c11e662c0012364aeaf5afc901107cd62b4a6fe72cf10deb01984c822ab00aba6dfad9
7
- data.tar.gz: 7b8c08c2ec99ea1f2847a1fd01029870b92571c6da41cf9733ba38df489e01de4a17ca4b361976c6f08bbac3bcd67723c0e351e4b7745171509875d6addf0a48
6
+ metadata.gz: 278088e76bba321edb14ca0010e1173e6162c52c5419689dad98468d8324e8dadf979c9a3658ba39ab8c2c40eb164e1483cfed3afe8ebcf56b8024cb3bdff6e3
7
+ data.tar.gz: d4658c957c973c1643b16c9ff0c8447917d9b5458e5e851e2b85e719b5d51f952030d1568d3ff65235645cc2e5b5c98c021749c4bd259bcccecf5e823e9c1004
checksums.yaml.gz.sig CHANGED
Binary file
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'async/service/configuration'
5
+ require 'async/service/controller'
6
+
7
+ require 'async/job/adapter/active_job/environment'
8
+
9
+ configuration = Async::Service::Configuration.build do
10
+ service "async-job-server" do
11
+ include Async::Job::Adapter::ActiveJob::Environment
12
+
13
+ root {ENV.fetch('RAILS_ROOT', Dir.pwd)}
14
+
15
+ # If you have multiple queues, you may want to run a separate server for each queue.
16
+ queue_name ENV.fetch('ASYNC_JOB_ADAPTER_ACTIVE_JOB_QUEUE_NAME', 'default')
17
+ end
18
+ end
19
+
20
+ Async::Service::Controller.run(configuration)
@@ -14,7 +14,11 @@ module Async
14
14
  module Job
15
15
  module Adapter
16
16
  module ActiveJob
17
+ # A dispatcher for managing multiple backends.
17
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.
18
22
  def initialize(backends, aliases = {})
19
23
  @backends = backends
20
24
  @aliases = aliases
@@ -22,10 +26,14 @@ module Async
22
26
  @pipelines = {}
23
27
  end
24
28
 
29
+ # @attribute [Hash(String, Proc)] The backends to use for processing jobs.
25
30
  attr :backends
26
31
 
32
+ # @attribute [Hash(String, String)] The aliases for the backends.
27
33
  attr :aliases
28
34
 
35
+ # Lookup a pipeline by name, constructing it if necessary using the given backend.
36
+ # @parameter name [String] The name of the pipeline/backend.
29
37
  def [](name)
30
38
  @pipelines.fetch(name) do
31
39
  backend = @backends.fetch(name)
@@ -33,18 +41,21 @@ module Async
33
41
  end
34
42
  end
35
43
 
44
+ # Enqueue a job for processing.
36
45
  def enqueue(job)
37
46
  name = @aliases.fetch(job.queue_name, job.queue_name)
38
47
 
39
48
  self[name].producer.enqueue(job)
40
49
  end
41
50
 
51
+ # Enqueue a job for processing at a specific time.
42
52
  def enqueue_at(job, timestamp)
43
53
  name = @aliases.fetch(job.queue_name, job.queue_name)
44
54
 
45
55
  self[name].producer.enqueue_at(job, timestamp)
46
56
  end
47
57
 
58
+ # Start processing jobs in the given pipeline.
48
59
  def start(name)
49
60
  self[name].consumer.start
50
61
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2024, by Samuel Williams.
5
+
6
+ require_relative 'service'
7
+
8
+ module Async
9
+ module Job
10
+ module Adapter
11
+ module ActiveJob
12
+ # The environment for the ActiveJob server.
13
+ module Environment
14
+ # The service class to use.
15
+ def service_class
16
+ Service
17
+ end
18
+
19
+ # The name of the queue to use.
20
+ def queue_name
21
+ "default"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -9,11 +9,13 @@ module Async
9
9
  module Job
10
10
  module Adapter
11
11
  module ActiveJob
12
+ # An executor for processing jobs using `ActiveJob`.
12
13
  class Executor
13
14
  def initialize(delegate = nil)
14
15
  @delegate = delegate
15
16
  end
16
17
 
18
+ # Execute the given job.
17
19
  def call(job)
18
20
  # Console.debug(self, "Executing job...", id: job["job_id"])
19
21
  ::ActiveJob::Base.execute(job)
@@ -7,16 +7,19 @@ module Async
7
7
  module Job
8
8
  module Adapter
9
9
  module ActiveJob
10
+ # An interface for `ActiveJob` that allows you to use `Async::Job` as the backend.
10
11
  class Interface
11
12
  def initialize(delegate)
12
13
  @delegate = delegate
13
14
  end
14
15
 
16
+ # Enqueue a job for processing.
15
17
  def enqueue(job)
16
18
  # Console.debug(self, "Enqueueing job...", id: job.job_id)
17
19
  @delegate.call(serialize(job))
18
20
  end
19
21
 
22
+ # Enqueue a job for processing at a specific time.
20
23
  def enqueue_at(job, timestamp)
21
24
  # We assume the given timestamp is the same as `job.scheduled_at` which is true in every case we've seen so far.
22
25
  # Console.debug(self, "Scheduling job...", id: job.job_id, scheduled_at: job.scheduled_at)
@@ -8,15 +8,15 @@ require 'thread/local'
8
8
 
9
9
  require_relative 'dispatcher'
10
10
 
11
- class Thread
12
- attr_accessor :async_job_adapter_active_job_dispatcher
13
- end
11
+ Thread.attr_accessor :async_job_adapter_active_job_dispatcher
14
12
 
15
13
  module Async
16
14
  module Job
17
15
  module Adapter
18
16
  module ActiveJob
17
+ # A Rails-specific adapter for `ActiveJob` that allows you to use `Async::Job` as the backend.
19
18
  class Railtie < ::Rails::Railtie
19
+ # The default pipeline for processing jobs, using the `Inline` backend.
20
20
  DEFAULT_PIPELINE = proc do
21
21
  queue Async::Job::Backend::Inline
22
22
  end
@@ -26,10 +26,16 @@ module Async
26
26
  @aliases = {}
27
27
  end
28
28
 
29
+ # The backends that are available for processing jobs.
29
30
  attr :backends
30
31
 
32
+ # The aliases for the backends.
31
33
  attr :aliases
32
34
 
35
+ # Define a new backend for processing jobs.
36
+ # @parameter name [String] The name of the backend.
37
+ # @parameter aliases [Array(String)] The aliases for the backend.
38
+ # @parameter block [Proc] The block that defines the backend.
33
39
  def backend_for(name, *aliases, &block)
34
40
  @backends[name] = block
35
41
 
@@ -38,6 +44,7 @@ module Async
38
44
  end
39
45
  end
40
46
 
47
+ # Define an alias for a backend.
41
48
  def alias_for(name, *aliases)
42
49
  aliases.each do |alias_name|
43
50
  @aliases[alias_name] = name
@@ -51,29 +58,37 @@ module Async
51
58
  @aliases = aliases
52
59
  end
53
60
 
61
+ # The dispatcher for the current thread.
54
62
  def dispatcher
55
63
  Thread.current.async_job_adapter_active_job_dispatcher ||= Dispatcher.new(@backends)
56
64
  end
57
65
 
66
+ # Enqueue a job to be processed at a specific time.
58
67
  def enqueue_at(job, timestamp)
59
68
  dispatcher.enqueue_at(job, timestamp)
60
69
  end
61
70
 
71
+ # Enqueue a job to be processed as soon as possible.
62
72
  def enqueue(job)
63
73
  dispatcher.enqueue(job)
64
74
  end
65
75
 
76
+ # Start processing jobs in the queue with the given name.
77
+ # @parameter name [String] The name of the backend.
66
78
  def start(name)
67
79
  dispatcher.start(name)
68
80
  end
69
81
  end
70
82
 
83
+ # Start the job server with the given name.
71
84
  def start(name = "default")
72
85
  config.active_job.queue_adapter.start(name)
73
86
  end
74
87
 
88
+ DEFAULT_QUEUE_ADAPTER = ThreadLocalDispatcher.new(self.backends, self.aliases)
89
+
75
90
  config.async_job = self
76
- config.active_job.queue_adapter = ThreadLocalDispatcher.new(self.backends, self.aliases)
91
+ config.active_job.queue_adapter = DEFAULT_QUEUE_ADAPTER
77
92
  end
78
93
  end
79
94
  end
@@ -9,21 +9,9 @@ module Async
9
9
  module Job
10
10
  module Adapter
11
11
  module ActiveJob
12
+ # A job server that can be run as a service.
12
13
  class Service < Async::Service::Generic
13
- module Environment
14
- def service_class
15
- Service
16
- end
17
-
18
- def queue_name
19
- "default"
20
- end
21
- end
22
-
23
- def self.included(base)
24
- base.include(Environment)
25
- end
26
-
14
+ # Load the Rails environment and start the job server.
27
15
  def setup(container)
28
16
  container.run(name: self.name, restart: true) do |instance|
29
17
  evaluator = @environment.evaluator
@@ -7,7 +7,7 @@ module Async
7
7
  module Job
8
8
  module Adapter
9
9
  module ActiveJob
10
- VERSION = "0.6.0"
10
+ VERSION = "0.7.1"
11
11
  end
12
12
  end
13
13
  end
data/readme.md CHANGED
@@ -6,45 +6,9 @@ Provides an adapter for ActiveJob on top of `Async::Job`.
6
6
 
7
7
  ## Usage
8
8
 
9
- Basically, just add this gem to your gemfile:
9
+ Please see the [project documentation](https://socketry.github.io/async-job-adapter-active_job/) for more details.
10
10
 
11
- ``` shell
12
- $ bundle add async-job-adapter-active_job
13
- ```
14
-
15
- To run a server, create a service file, e.g. `job-server.rb` with the following content:
16
-
17
- ``` ruby
18
- #!/usr/bin/env async-service
19
-
20
- require 'async/job/adapter/active_job/service'
21
-
22
- service "job-server" do
23
- include Async::Job::Adapter::ActiveJob::Service
24
- end
25
- ```
26
-
27
- Then run it:
28
-
29
- ``` shell
30
- $ bundle exec ./job-server.rb
31
- ```
32
-
33
- ### Configuration
34
-
35
- ``` ruby
36
- Rails.application.configure do
37
- config.async_job.backend_for :default, :critical do
38
- queue Async::Job::Backend::Redis, endpoint: Async::IO::Endpoint.tcp('redis.local')
39
- end
40
-
41
- config.async_job.aliases_for :default, :email
42
-
43
- config.async_job.backend_for :local do
44
- queue Async::Job::Backend::Inline
45
- end
46
- end
47
- ```
11
+ - [Getting Started](https://socketry.github.io/async-job-adapter-active_job/guides/getting-started/index) - This guide explains how to get started with the `async-job-active_job-adapter` gem.
48
12
 
49
13
  ## Contributing
50
14
 
@@ -58,8 +22,8 @@ We welcome contributions to this project.
58
22
 
59
23
  ### Developer Certificate of Origin
60
24
 
61
- This project uses the [Developer Certificate of Origin](https://developercertificate.org/). All contributors to this project must agree to this document to have their contributions accepted.
25
+ In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.
62
26
 
63
- ### Contributor Covenant
27
+ ### Community Guidelines
64
28
 
65
- This project is governed by the [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
29
+ This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.
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.6.0
4
+ version: 0.7.1
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-03-22 00:00:00.000000000 Z
40
+ date: 2024-08-02 00:00:00.000000000 Z
41
41
  dependencies:
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: async-job
@@ -45,28 +45,28 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: 0.4.1
48
+ version: '0.5'
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.4.1
55
+ version: '0.5'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: async-service
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: 0.8.0
62
+ version: '0.12'
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: 0.8.0
69
+ version: '0.12'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: thread-local
72
72
  requirement: !ruby/object:Gem::Requirement
@@ -83,12 +83,15 @@ dependencies:
83
83
  version: '0'
84
84
  description:
85
85
  email:
86
- executables: []
86
+ executables:
87
+ - async-job-adapter-active_job-server
87
88
  extensions: []
88
89
  extra_rdoc_files: []
89
90
  files:
91
+ - bin/async-job-adapter-active_job-server
90
92
  - lib/async/job/adapter/active_job.rb
91
93
  - lib/async/job/adapter/active_job/dispatcher.rb
94
+ - lib/async/job/adapter/active_job/environment.rb
92
95
  - lib/async/job/adapter/active_job/executor.rb
93
96
  - lib/async/job/adapter/active_job/interface.rb
94
97
  - lib/async/job/adapter/active_job/railtie.rb
@@ -96,11 +99,12 @@ files:
96
99
  - lib/async/job/adapter/active_job/version.rb
97
100
  - license.md
98
101
  - readme.md
99
- homepage:
102
+ homepage: https://github.com/socketry/async-job-adapter-active_job
100
103
  licenses:
101
104
  - MIT
102
105
  metadata:
103
- documentation_uri: https://socketry.github.io/async-job-adapter-active_job
106
+ documentation_uri: https://socketry.github.io/async-job-adapter-active_job/
107
+ source_code_uri: https://github.com/socketry/async-job-adapter-active_job.git
104
108
  post_install_message:
105
109
  rdoc_options: []
106
110
  require_paths:
@@ -109,14 +113,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
113
  requirements:
110
114
  - - ">="
111
115
  - !ruby/object:Gem::Version
112
- version: '3.0'
116
+ version: '3.1'
113
117
  required_rubygems_version: !ruby/object:Gem::Requirement
114
118
  requirements:
115
119
  - - ">="
116
120
  - !ruby/object:Gem::Version
117
121
  version: '0'
118
122
  requirements: []
119
- rubygems_version: 3.5.3
123
+ rubygems_version: 3.5.11
120
124
  signing_key:
121
125
  specification_version: 4
122
126
  summary: A asynchronous job queue for Ruby on Rails.
metadata.gz.sig CHANGED
Binary file