active_interaction-active_job 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +32 -1
- data/lib/active_interaction/active_job.rb +8 -1
- data/lib/active_interaction/active_job/core.rb +3 -16
- data/lib/active_interaction/active_job/sidekiq/configured_job.rb +21 -0
- data/lib/active_interaction/active_job/sidekiq/core.rb +10 -0
- data/lib/active_interaction/active_job/sidekiq/job_helper.rb +6 -0
- data/lib/active_interaction/active_job/version.rb +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c07d78350fd9b3ccc7e99ad7d238fd7e541f5f3
|
4
|
+
data.tar.gz: 58ed3d122bf95d64de98b165c3aaa675f55c38cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 794741cffd5a6ed5dac4018e536b6bf5c63d6e7154f03224f6f40f5215d12833375f059ae8ca3cebf736ed3123c52aa7fc70ae62f16d61ef1ede25f236e672f0
|
7
|
+
data.tar.gz: 39f2e048951ea7201247c747a3b44bf6e9dafd205c95c6d71f867eb36d2cf95da0d56b9cbe8bf1810d5a39e030fb8bfe9200fd4b7b38a0b4116236553ea841b2
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
### 0.3.0
|
2
|
+
|
3
|
+
- **BREAKING CHANGE** `class.async` method is removed, use `delay.run` or alias it yourself
|
4
|
+
- **BREAKING CHANGE** Job class is no longer is created by default, you need to manually create it yourself
|
5
|
+
- added sidekiq support
|
6
|
+
- added alias `job` to `active_job` interaction class method
|
data/README.md
CHANGED
@@ -20,7 +20,10 @@ gem 'active_interaction-active_job'
|
|
20
20
|
```ruby
|
21
21
|
class Add < ActiveInteraction::Base
|
22
22
|
include ActiveInteraction::ActiveJob::Core
|
23
|
-
|
23
|
+
|
24
|
+
class Job < ActiveJob::Base
|
25
|
+
include ActiveInteraction::ActiveJob::JobHelper
|
26
|
+
end
|
24
27
|
|
25
28
|
integer :x, :y
|
26
29
|
|
@@ -90,6 +93,34 @@ AddOrDivide.async(x: 4, y: 2, divide: true) # same as above
|
|
90
93
|
AddOrDivide.delay(queue_name: 'fast', wait: 1.week).run(x: 4, y: 2, divide: true)
|
91
94
|
```
|
92
95
|
|
96
|
+
## Sidekiq without ActiveJob
|
97
|
+
|
98
|
+
You can use sidekiq directly if you need more control. Sidekiq integration comes with default GlobalID support.
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
class BaseInteraction < ActiveInteraction::Base
|
102
|
+
include ActiveInteraction::ActiveJob::Sidekiq::Core
|
103
|
+
|
104
|
+
class Job
|
105
|
+
include Sidekiq::Worker
|
106
|
+
include ActiveInteraction::ActiveJob::Sidekiq::JobHelper
|
107
|
+
|
108
|
+
sidekiq_options queue: 'default'
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
class Add < BaseInteraction
|
113
|
+
job do
|
114
|
+
sidekiq_options queue: 'critical'
|
115
|
+
end
|
116
|
+
|
117
|
+
def execute
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
Add.delay(wait: 1.minute, queue: 'slow').run
|
122
|
+
```
|
123
|
+
|
93
124
|
|
94
125
|
## Development
|
95
126
|
|
@@ -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,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 klass
|
5
|
+
def define_job_class klass
|
10
6
|
unless const_defined?(:Job, false)
|
11
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)
|
@@ -29,14 +22,8 @@ module ActiveInteraction::ActiveJob::Core
|
|
29
22
|
subclass.define_job_class job_class
|
30
23
|
end
|
31
24
|
|
32
|
-
def
|
25
|
+
def delay options = {}
|
33
26
|
::ActiveInteraction::ActiveJob::ConfiguredJob.new(job_class, options)
|
34
27
|
end
|
35
|
-
|
36
|
-
alias_method :delay, :set
|
37
|
-
|
38
|
-
def async *args
|
39
|
-
delay.run! *args
|
40
|
-
end
|
41
28
|
end
|
42
29
|
end
|
@@ -0,0 +1,21 @@
|
|
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 @options[:wait]
|
11
|
+
scope.perform_in @options[:wait], *args
|
12
|
+
elsif @options[:wait_until]
|
13
|
+
scope.perform_at @options[:wait_until], *args
|
14
|
+
else
|
15
|
+
scope.perform_async *args
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
alias_method :run!, :perform_later
|
20
|
+
alias_method :run, :perform_later
|
21
|
+
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
|
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.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Katunin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -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:
|
@@ -122,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
126
|
version: '0'
|
123
127
|
requirements: []
|
124
128
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.
|
129
|
+
rubygems_version: 2.6.8
|
126
130
|
signing_key:
|
127
131
|
specification_version: 4
|
128
132
|
summary: Add ActiveJob support to ActiveInteraction gem
|