activejob-dispatch_rider 1.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +11 -0
- data/README.md +6 -0
- data/activejob-dispatch_rider.gemspec +3 -3
- data/lib/activejob/dispatch_rider.rb +7 -4
- data/lib/activejob/dispatch_rider/handler_registrar_fallback.rb +16 -0
- data/lib/activejob/dispatch_rider/job_handler.rb +10 -0
- data/lib/activejob/dispatch_rider/version.rb +1 -1
- data/lib/activejob/queue_adapters/dispatch_rider_adapter.rb +17 -12
- data/spec/{dispatch_rider_active_job_handler_spec.rb → activejob/dispatch_rider/job_handler_spec.rb} +2 -2
- data/spec/activejob/queue_adapters/dispatch_rider_adapter_spec.rb +10 -4
- data/spec/dispatch_rider/registrars/handler_spec.rb +7 -0
- data/spec/spec_helper.rb +17 -2
- metadata +19 -17
- data/lib/dispatch_rider_active_job_handler.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: db7c7477074fd23481d8a9b69e679543200f5102e9c50793edef4b329f211831
|
4
|
+
data.tar.gz: 14afa06d887d740449067514cfc74e98665f31da6fdc5bab1f73c72288624ac5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0e2644b009e6def66cbfca386d03f9120db66203ee4332922f47a2d2c69bb7eab2f31ecaa9348b6eb5f104b8db9954a211f8e8aace6008130194ba02dc9058a
|
7
|
+
data.tar.gz: c755ec69b3923b912c8d9d77095343ce1da6f2a6acd2bf7907f22a85987422bf4a7fafc97fff5e2c3207f8811e4d46e2eecddabdf3c45b92d65c397c8d11a6a2
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -139,3 +139,9 @@ CallAndWelcomeCustomer.perform_later Customer.find_by_name!("Smith"),
|
|
139
139
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
140
140
|
4. Push to the branch (`git push origin my-new-feature`)
|
141
141
|
5. Create a new Pull Request
|
142
|
+
|
143
|
+
## Contributors
|
144
|
+
|
145
|
+
Special thanks to those who contributed to this project. :smile:
|
146
|
+
|
147
|
+
* [@fredbaa](https://github.com/fredbaa)
|
@@ -18,10 +18,10 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "activejob"
|
22
|
-
spec.add_dependency "dispatch-rider"
|
21
|
+
spec.add_dependency "activejob", '~> 5.1.0'
|
22
|
+
spec.add_dependency "dispatch-rider", "~> 1.7"
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.7"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
25
|
spec.add_development_dependency "rspec"
|
26
|
-
spec.add_development_dependency "
|
26
|
+
spec.add_development_dependency "sqlite3"
|
27
27
|
end
|
@@ -1,12 +1,15 @@
|
|
1
|
-
require "activejob/dispatch_rider/version"
|
2
1
|
require "active_job"
|
3
2
|
require "dispatch-rider"
|
4
|
-
require "dispatch_rider_active_job_handler"
|
5
3
|
|
6
4
|
module ActiveJob
|
7
5
|
module DispatchRider
|
8
|
-
# Your code goes here...
|
9
6
|
end
|
10
7
|
end
|
11
8
|
|
12
|
-
|
9
|
+
require_relative "dispatch_rider/version"
|
10
|
+
require_relative "dispatch_rider/job_handler"
|
11
|
+
require_relative "dispatch_rider/handler_registrar_fallback"
|
12
|
+
require_relative "queue_adapters/dispatch_rider_adapter"
|
13
|
+
|
14
|
+
# Handle all unregistered messages as messages coming from ActiveJobs.
|
15
|
+
DispatchRider::Registrars::Handler.prepend ActiveJob::DispatchRider::HandlerRegistrarFallback
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ActiveJob
|
2
|
+
module DispatchRider
|
3
|
+
# This module is prepended to `DispatchRider::Registrars::Handler` to allow it to cover any
|
4
|
+
# ActiveJob messages. The assumption is that if the message's subject doesn't have a registered
|
5
|
+
# native `DispatchRider::Handler` then the job is delegated to
|
6
|
+
# `ActiveJob::DispatchRider::JobHandler`. `ActiveJob::DispatchRider::JobHandler` essentially
|
7
|
+
# just let ActiveJob process the message as it would process them normally.
|
8
|
+
module HandlerRegistrarFallback
|
9
|
+
def fetch(*)
|
10
|
+
super
|
11
|
+
rescue ::DispatchRider::NotRegistered
|
12
|
+
JobHandler
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -2,21 +2,17 @@ module ActiveJob
|
|
2
2
|
module QueueAdapters
|
3
3
|
# Adds support for DispatchRider to ActiveJob.
|
4
4
|
class DispatchRiderAdapter
|
5
|
-
class << self
|
6
5
|
# @param [ActiveJob::Base] job
|
7
6
|
def enqueue(job)
|
8
|
-
publisher.publish
|
9
|
-
message: {
|
10
|
-
subject: "dispatch_rider_active_job_handler",
|
11
|
-
body: job.serialize
|
12
|
-
}
|
7
|
+
publisher.publish job_details_for(job)
|
13
8
|
end
|
14
9
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
10
|
+
# @param [ActiveJob::Base] job
|
11
|
+
# @param [Float] scheduled_at - float representing time (blame AJ)
|
12
|
+
def enqueue_at(job, scheduled_at)
|
13
|
+
scheduled_job_details = job_details_for(job).merge(scheduled_at: Time.at(scheduled_at))
|
14
|
+
|
15
|
+
::DispatchRider::ScheduledJob.create! scheduled_job_details
|
20
16
|
end
|
21
17
|
|
22
18
|
private
|
@@ -24,7 +20,16 @@ module ActiveJob
|
|
24
20
|
def publisher
|
25
21
|
@publisher ||= ::DispatchRider::Publisher.new
|
26
22
|
end
|
27
|
-
|
23
|
+
|
24
|
+
def job_details_for(job)
|
25
|
+
{
|
26
|
+
destinations: Array(job.queue_name),
|
27
|
+
message: {
|
28
|
+
subject: job.class.name.underscore,
|
29
|
+
body: job.serialize.merge(guid: job.job_id)
|
30
|
+
}
|
31
|
+
}
|
32
|
+
end
|
28
33
|
end
|
29
34
|
end
|
30
35
|
end
|
data/spec/{dispatch_rider_active_job_handler_spec.rb → activejob/dispatch_rider/job_handler_spec.rb}
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe ActiveJob::DispatchRider::JobHandler do
|
4
4
|
|
5
5
|
let!(:job_class) {
|
6
6
|
job_class = Class.new(ActiveJob::Base) do
|
@@ -27,7 +27,7 @@ describe DispatchRiderActiveJobHandler do
|
|
27
27
|
"_aj_symbol_keys" => ["foo"]
|
28
28
|
}
|
29
29
|
],
|
30
|
-
"guid" => "
|
30
|
+
"guid" => "8b71ac6b-2854-4287-8d1b-15085b70280b",
|
31
31
|
}
|
32
32
|
}
|
33
33
|
|
@@ -50,8 +50,9 @@ describe ActiveJob::QueueAdapters::DispatchRiderAdapter do
|
|
50
50
|
example("queued item") {
|
51
51
|
foo_job_class.perform_later foo: "bar"
|
52
52
|
|
53
|
-
expect(foo_queued_item["subject"]).to eq("
|
53
|
+
expect(foo_queued_item["subject"]).to eq("foo_aj_job")
|
54
54
|
expect(foo_queued_item["body"]["job_class"]).to eq("FooAjJob")
|
55
|
+
expect(foo_queued_item["body"]["guid"]).to eq(foo_queued_item["body"]["job_id"])
|
55
56
|
expect(foo_queued_item["body"]["queue_name"]).to eq("foo")
|
56
57
|
expect(foo_queued_item["body"]["arguments"].first).to include("foo" => "bar")
|
57
58
|
}
|
@@ -64,10 +65,15 @@ describe ActiveJob::QueueAdapters::DispatchRiderAdapter do
|
|
64
65
|
end
|
65
66
|
|
66
67
|
describe ".enqueue_at" do
|
67
|
-
let(:
|
68
|
-
let(:timestamp) { Time.now }
|
68
|
+
let(:tomorrow_midnight) { Date.tomorrow.midnight }
|
69
69
|
|
70
|
-
example {
|
70
|
+
example {
|
71
|
+
expect {
|
72
|
+
foo_job_class.set(wait_until: tomorrow_midnight).perform_later foo: "bar"
|
73
|
+
}.to change(DispatchRider::ScheduledJob, :count).by 1
|
74
|
+
|
75
|
+
expect(DispatchRider::ScheduledJob.last.scheduled_at).to eq tomorrow_midnight
|
76
|
+
}
|
71
77
|
end
|
72
78
|
end
|
73
79
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
require "
|
2
|
-
CodeClimate::TestReporter.start
|
1
|
+
require "sqlite3"
|
3
2
|
|
4
3
|
require "activejob/dispatch_rider"
|
5
4
|
|
@@ -109,4 +108,20 @@ RSpec.configure do |config|
|
|
109
108
|
# as the one that triggered the failure.
|
110
109
|
Kernel.srand config.seed
|
111
110
|
=end
|
111
|
+
|
112
|
+
config.before(:suite) do
|
113
|
+
FileUtils.mkdir_p "tmp"
|
114
|
+
FileUtils.rm_f "tmp/lite.db"
|
115
|
+
FileUtils.rm_rf "spectmp"
|
116
|
+
SQLite3::Database.new "tmp/lite.db"
|
117
|
+
ActiveRecord::Base.establish_connection adapter: :sqlite3, database: File.dirname(__FILE__) + "tmp/lite.db"
|
118
|
+
ActiveRecord::Schema.define(version: 1) do
|
119
|
+
extend DispatchRider::ScheduledJob::Migration
|
120
|
+
create_scheduled_jobs_table
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
config.after do
|
125
|
+
DispatchRider::ScheduledJob.destroy_all
|
126
|
+
end
|
112
127
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activejob-dispatch_rider
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ronald Maravilla
|
@@ -9,36 +9,36 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-08-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activejob
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 5.1.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - "
|
25
|
+
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 5.1.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: dispatch-rider
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - "
|
32
|
+
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
34
|
+
version: '1.7'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - "
|
39
|
+
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
41
|
+
version: '1.7'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: bundler
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,7 +82,7 @@ dependencies:
|
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
|
-
name:
|
85
|
+
name: sqlite3
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
88
|
- - ">="
|
@@ -105,17 +105,20 @@ extra_rdoc_files: []
|
|
105
105
|
files:
|
106
106
|
- ".gitignore"
|
107
107
|
- ".rspec"
|
108
|
+
- ".travis.yml"
|
108
109
|
- Gemfile
|
109
110
|
- README.md
|
110
111
|
- Rakefile
|
111
112
|
- activejob-dispatch_rider.gemspec
|
112
113
|
- circle.yml
|
113
114
|
- lib/activejob/dispatch_rider.rb
|
115
|
+
- lib/activejob/dispatch_rider/handler_registrar_fallback.rb
|
116
|
+
- lib/activejob/dispatch_rider/job_handler.rb
|
114
117
|
- lib/activejob/dispatch_rider/version.rb
|
115
118
|
- lib/activejob/queue_adapters/dispatch_rider_adapter.rb
|
116
|
-
-
|
119
|
+
- spec/activejob/dispatch_rider/job_handler_spec.rb
|
117
120
|
- spec/activejob/queue_adapters/dispatch_rider_adapter_spec.rb
|
118
|
-
- spec/
|
121
|
+
- spec/dispatch_rider/registrars/handler_spec.rb
|
119
122
|
- spec/spec_helper.rb
|
120
123
|
homepage: https://github.com/payrollhero/activejob-dispatch_rider
|
121
124
|
licenses:
|
@@ -136,13 +139,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
139
|
- !ruby/object:Gem::Version
|
137
140
|
version: '0'
|
138
141
|
requirements: []
|
139
|
-
|
140
|
-
rubygems_version: 2.2.2
|
142
|
+
rubygems_version: 3.0.9
|
141
143
|
signing_key:
|
142
144
|
specification_version: 4
|
143
145
|
summary: "'ActiveJob::DispatchRider' adds `DispatchRider` support for `ActiveJob`."
|
144
146
|
test_files:
|
147
|
+
- spec/activejob/dispatch_rider/job_handler_spec.rb
|
145
148
|
- spec/activejob/queue_adapters/dispatch_rider_adapter_spec.rb
|
146
|
-
- spec/
|
149
|
+
- spec/dispatch_rider/registrars/handler_spec.rb
|
147
150
|
- spec/spec_helper.rb
|
148
|
-
has_rdoc:
|