active_interaction-active_job 0.1.0 → 0.3.2
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 +5 -5
- data/CHANGELOG.md +12 -0
- data/README.md +36 -5
- data/active_interaction-active_job.gemspec +2 -2
- data/lib/active_interaction/active_job.rb +8 -1
- data/lib/active_interaction/active_job/configured_job.rb +3 -10
- data/lib/active_interaction/active_job/core.rb +6 -19
- data/lib/active_interaction/active_job/job_helper.rb +6 -2
- data/lib/active_interaction/active_job/sidekiq/configured_job.rb +25 -0
- data/lib/active_interaction/active_job/sidekiq/core.rb +10 -0
- data/lib/active_interaction/active_job/sidekiq/job_helper.rb +15 -0
- data/lib/active_interaction/active_job/version.rb +1 -1
- metadata +11 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7fa4e8c87d430b63f62d6d62a9ed877e4b243ac0da4935c47f38d26a421f7bf5
|
4
|
+
data.tar.gz: c0365d6efc7e71654d19f6a80fd17004d2a724fb09f2eb4dc0f3e2e7dedc1a36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 017d448d6431190a8b15deb81cfd0d507c5911aaba8481a625a684d2fc1f9af334fe7cbc82bc361422b62131346da28e7ddf796af1ffb03f17448d676936cd06
|
7
|
+
data.tar.gz: 468d32049f3a229cf3f6e1b0c728cfd51126ceadea09b20042208e537ea94bc80d8216e1953d4d43675037e59472fe6422077256d9fc971d4379ce0da2682b36
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
### 0.3.2
|
2
|
+
- Fix rails 6 deprecation warning (#2)
|
3
|
+
|
4
|
+
### 0.3.1
|
5
|
+
- Add support for Sidekiq Enterprise Encryption
|
6
|
+
|
7
|
+
### 0.3.0
|
8
|
+
|
9
|
+
- **BREAKING CHANGE** `class.async` method is removed, use `delay.run` or alias it yourself
|
10
|
+
- **BREAKING CHANGE** Job class is no longer is created by default, you need to manually create it yourself
|
11
|
+
- added sidekiq support
|
12
|
+
- added alias `job` to `active_job` interaction class method
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# ActiveInteraction::ActiveJob
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/active_interaction-active_job)
|
4
|
+
|
3
5
|
This gem adds [active_job](http://edgeguides.rubyonrails.org/active_job_basics.html) support to [active_interaction](https://github.com/orgsync/active_interaction) gem.
|
4
6
|
|
5
7
|
With this gem you no longer need to create a separate Job class for the each interaction, this gem does it automatically for you.
|
@@ -18,7 +20,10 @@ gem 'active_interaction-active_job'
|
|
18
20
|
```ruby
|
19
21
|
class Add < ActiveInteraction::Base
|
20
22
|
include ActiveInteraction::ActiveJob::Core
|
21
|
-
|
23
|
+
|
24
|
+
class Job < ActiveJob::Base
|
25
|
+
include ActiveInteraction::ActiveJob::JobHelper
|
26
|
+
end
|
22
27
|
|
23
28
|
integer :x, :y
|
24
29
|
|
@@ -29,8 +34,6 @@ end
|
|
29
34
|
|
30
35
|
|
31
36
|
Add.delay.run(x: 1, y: 2)
|
32
|
-
Add.async(x: 1, y: 2) # same as above
|
33
|
-
|
34
37
|
Add.delay(queue_name: 'fast', wait: 1.week).run(x: 1, y: 2)
|
35
38
|
```
|
36
39
|
|
@@ -83,11 +86,39 @@ end
|
|
83
86
|
|
84
87
|
|
85
88
|
AddOrDivide.delay.run(x: 4, y: 2, divide: true)
|
86
|
-
AddOrDivide.async(x: 4, y: 2, divide: true) # same as above
|
87
|
-
|
88
89
|
AddOrDivide.delay(queue_name: 'fast', wait: 1.week).run(x: 4, y: 2, divide: true)
|
89
90
|
```
|
90
91
|
|
92
|
+
## Sidekiq without ActiveJob
|
93
|
+
|
94
|
+
You can use sidekiq directly if you need more control. Sidekiq integration comes with default GlobalID support.
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
class BaseInteraction < ActiveInteraction::Base
|
98
|
+
include ActiveInteraction::ActiveJob::Sidekiq::Core
|
99
|
+
|
100
|
+
class Job
|
101
|
+
include Sidekiq::Worker
|
102
|
+
include ActiveInteraction::ActiveJob::Sidekiq::JobHelper
|
103
|
+
|
104
|
+
sidekiq_options queue: 'default'
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
class Add < BaseInteraction
|
109
|
+
job do
|
110
|
+
sidekiq_options queue: 'critical'
|
111
|
+
end
|
112
|
+
|
113
|
+
def execute
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
Add.delay(wait: 1.minute, queue: 'slow').run
|
118
|
+
```
|
119
|
+
|
120
|
+
In sidekiq mode `delay` method accepts anything sidekiq `set` [method](https://github.com/mperham/sidekiq/wiki/Advanced-Options#workers) (`queue`, `retry`, `backtrace`, etc) plus two additional: `wait` and `wait_until`.
|
121
|
+
|
91
122
|
|
92
123
|
## Development
|
93
124
|
|
@@ -25,6 +25,6 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_dependency "activesupport"
|
26
26
|
spec.add_dependency "active_interaction"
|
27
27
|
|
28
|
-
spec.add_development_dependency "bundler", "~> 1
|
29
|
-
spec.add_development_dependency "rake", "~>
|
28
|
+
spec.add_development_dependency "bundler", "~> 2.0.1"
|
29
|
+
spec.add_development_dependency "rake", "~> 13.0.1"
|
30
30
|
end
|
@@ -11,7 +11,14 @@ module ActiveInteraction
|
|
11
11
|
|
12
12
|
autoload :Core
|
13
13
|
autoload :ConfiguredJob
|
14
|
-
autoload :DefaultJob
|
15
14
|
autoload :JobHelper
|
15
|
+
|
16
|
+
module Sidekiq
|
17
|
+
extend ActiveSupport::Autoload
|
18
|
+
|
19
|
+
autoload :Core
|
20
|
+
autoload :ConfiguredJob
|
21
|
+
autoload :JobHelper
|
22
|
+
end
|
16
23
|
end
|
17
24
|
end
|
@@ -1,13 +1,6 @@
|
|
1
|
-
class ActiveInteraction::ActiveJob::ConfiguredJob
|
2
|
-
def initialize job_class, service_class, options={}
|
3
|
-
@options = options
|
4
|
-
@service_class = service_class
|
5
|
-
@job_class = job_class
|
6
|
-
end
|
1
|
+
class ActiveInteraction::ActiveJob::ConfiguredJob < ::ActiveJob::ConfiguredJob
|
7
2
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
3
|
+
alias_method :run!, :perform_later
|
4
|
+
alias_method :run, :perform_later
|
11
5
|
|
12
|
-
alias_method :run!, :run
|
13
6
|
end
|
@@ -1,24 +1,17 @@
|
|
1
1
|
module ActiveInteraction::ActiveJob::Core
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
|
-
included do
|
5
|
-
define_job_class
|
6
|
-
end
|
7
|
-
|
8
4
|
module ClassMethods
|
9
|
-
def define_job_class
|
5
|
+
def define_job_class klass
|
10
6
|
unless const_defined?(:Job, false)
|
11
|
-
const_set(:Job, Class.new(
|
7
|
+
const_set(:Job, Class.new(klass))
|
12
8
|
end
|
13
9
|
end
|
14
10
|
|
15
|
-
def default_job_class
|
16
|
-
ActiveInteraction::ActiveJob::DefaultJob
|
17
|
-
end
|
18
|
-
|
19
11
|
def active_job &block
|
20
12
|
job_class.class_exec(&block)
|
21
13
|
end
|
14
|
+
alias_method :job, :active_job
|
22
15
|
|
23
16
|
def job_class
|
24
17
|
const_get(:Job, false)
|
@@ -26,17 +19,11 @@ module ActiveInteraction::ActiveJob::Core
|
|
26
19
|
|
27
20
|
def inherited subclass
|
28
21
|
super
|
29
|
-
subclass.
|
22
|
+
subclass.define_job_class job_class
|
30
23
|
end
|
31
24
|
|
32
|
-
def
|
33
|
-
ActiveInteraction::ActiveJob::ConfiguredJob.new(job_class,
|
34
|
-
end
|
35
|
-
|
36
|
-
alias_method :delay, :set
|
37
|
-
|
38
|
-
def async *args
|
39
|
-
delay.run! *args
|
25
|
+
def delay options = {}
|
26
|
+
::ActiveInteraction::ActiveJob::ConfiguredJob.new(job_class, options)
|
40
27
|
end
|
41
28
|
end
|
42
29
|
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
module ActiveInteraction::ActiveJob::JobHelper
|
2
|
-
def perform
|
3
|
-
|
2
|
+
def perform *args
|
3
|
+
if self.class.respond_to?(:module_parent)
|
4
|
+
self.class.module_parent.run!(*args)
|
5
|
+
else
|
6
|
+
self.class.parent.run!(*args)
|
7
|
+
end
|
4
8
|
end
|
5
9
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class ActiveInteraction::ActiveJob::Sidekiq::ConfiguredJob < ::ActiveJob::ConfiguredJob
|
2
|
+
def perform_now(*args)
|
3
|
+
@job_class.run!(*args)
|
4
|
+
end
|
5
|
+
|
6
|
+
def perform_later(*args)
|
7
|
+
args = ActiveJob::Arguments.serialize(args)
|
8
|
+
scope = @job_class.set(@options.except(:wait, :wait_until))
|
9
|
+
|
10
|
+
if @job_class.sidekiq_options['encrypt']
|
11
|
+
args.prepend(nil)
|
12
|
+
end
|
13
|
+
|
14
|
+
if @options[:wait]
|
15
|
+
scope.perform_in @options[:wait], *args
|
16
|
+
elsif @options[:wait_until]
|
17
|
+
scope.perform_at @options[:wait_until], *args
|
18
|
+
else
|
19
|
+
scope.perform_async *args
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
alias_method :run!, :perform_later
|
24
|
+
alias_method :run, :perform_later
|
25
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module ActiveInteraction::ActiveJob::Sidekiq::Core
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
include ActiveInteraction::ActiveJob::Core
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def delay options = {}
|
7
|
+
::ActiveInteraction::ActiveJob::Sidekiq::ConfiguredJob.new(job_class, options)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ActiveInteraction::ActiveJob::Sidekiq::JobHelper
|
2
|
+
def perform *args
|
3
|
+
# support for sidekiq encrypted params
|
4
|
+
if args.length > 1 && args[0].nil?
|
5
|
+
args.shift
|
6
|
+
end
|
7
|
+
|
8
|
+
args = ActiveJob::Arguments.deserialize(args)
|
9
|
+
if self.class.respond_to?(:module_parent)
|
10
|
+
self.class.module_parent.run!(*args)
|
11
|
+
else
|
12
|
+
self.class.parent.run!(*args)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_interaction-active_job
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Katunin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -58,28 +58,28 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 2.0.1
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 2.0.1
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 13.0.1
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 13.0.1
|
83
83
|
description: Add ActiveJob support to ActiveInteraction gem
|
84
84
|
email:
|
85
85
|
- antulik@gmail.com
|
@@ -88,6 +88,7 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
|
+
- CHANGELOG.md
|
91
92
|
- CODE_OF_CONDUCT.md
|
92
93
|
- Gemfile
|
93
94
|
- LICENSE.txt
|
@@ -101,6 +102,9 @@ files:
|
|
101
102
|
- lib/active_interaction/active_job/core.rb
|
102
103
|
- lib/active_interaction/active_job/default_job.rb
|
103
104
|
- lib/active_interaction/active_job/job_helper.rb
|
105
|
+
- lib/active_interaction/active_job/sidekiq/configured_job.rb
|
106
|
+
- lib/active_interaction/active_job/sidekiq/core.rb
|
107
|
+
- lib/active_interaction/active_job/sidekiq/job_helper.rb
|
104
108
|
- lib/active_interaction/active_job/version.rb
|
105
109
|
homepage: https://github.com/antulik/active_interaction-active_job
|
106
110
|
licenses:
|
@@ -121,8 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
125
|
- !ruby/object:Gem::Version
|
122
126
|
version: '0'
|
123
127
|
requirements: []
|
124
|
-
|
125
|
-
rubygems_version: 2.4.5
|
128
|
+
rubygems_version: 3.0.3
|
126
129
|
signing_key:
|
127
130
|
specification_version: 4
|
128
131
|
summary: Add ActiveJob support to ActiveInteraction gem
|