async-job-adapter-active_job 0.6.0 → 0.7.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/bin/async-job-adapter-active_job-server +19 -0
- data/lib/async/job/adapter/active_job/dispatcher.rb +11 -0
- data/lib/async/job/adapter/active_job/environment.rb +27 -0
- data/lib/async/job/adapter/active_job/executor.rb +2 -0
- data/lib/async/job/adapter/active_job/interface.rb +3 -0
- data/lib/async/job/adapter/active_job/railtie.rb +16 -3
- data/lib/async/job/adapter/active_job/service.rb +2 -14
- data/lib/async/job/adapter/active_job/version.rb +1 -1
- data/readme.md +2 -38
- data.tar.gz.sig +0 -0
- metadata +14 -10
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65f9e22e242a8c2d9c96fd81e52e5e4ec0d4eeddda402544f808b59d3633cbdb
|
4
|
+
data.tar.gz: e1cf84731daf4ec7d0739fce4d205544c66a111a753b4817939379d816a22a1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cbb5ac1d912f5a1e59ab1d781f8caf3d5de955722195bf407301c1a6bb49a2933d94e3315ad14aa102986be58b70b7b0260e3a8f11b6770c9d30b4b1d1f074a
|
7
|
+
data.tar.gz: 575b40692b1d57984bae97ab7308a194821733299beb0efc03d9d53ba05a9b45a30138c4412d1e0404622c12c95ac4add153118f5fe86374e7423dfc4d40ace8
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'async/service/configuration'
|
4
|
+
require 'async/service/controller'
|
5
|
+
|
6
|
+
require 'async/job/adapter/active_job/environment'
|
7
|
+
|
8
|
+
configuration = Async::Service::Configuration.build do
|
9
|
+
service "async-job-server" do
|
10
|
+
include Async::Job::Adapter::ActiveJob::Environment
|
11
|
+
|
12
|
+
root {ENV.fetch('RAILS_ROOT', Dir.pwd)}
|
13
|
+
|
14
|
+
# If you have multiple queues, you may want to run a separate server for each queue.
|
15
|
+
queue_name ENV.fetch('ASYNC_JOB_ADAPTER_ACTIVE_JOB_QUEUE_NAME', 'default')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
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
|
-
|
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,23 +58,29 @@ 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
|
@@ -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
|
-
|
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
|
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
|
-
|
9
|
+
Please see the [project documentation](https://socketry.github.io/async-job-adapter-active_job/) for more details.
|
10
10
|
|
11
|
-
|
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
|
|
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.
|
4
|
+
version: 0.7.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-
|
40
|
+
date: 2024-04-07 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.
|
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.
|
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.
|
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.
|
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,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
113
|
requirements:
|
110
114
|
- - ">="
|
111
115
|
- !ruby/object:Gem::Version
|
112
|
-
version: '3.
|
116
|
+
version: '3.1'
|
113
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
118
|
requirements:
|
115
119
|
- - ">="
|
metadata.gz.sig
CHANGED
Binary file
|