active_interaction-active_job 0.1.0 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3fdaf56bdba70f7b40df2b577add8be2f91cc3d3
4
- data.tar.gz: be1fd8057bdcf537341cf6e21cd15960005ebb7a
2
+ SHA256:
3
+ metadata.gz: 7fa4e8c87d430b63f62d6d62a9ed877e4b243ac0da4935c47f38d26a421f7bf5
4
+ data.tar.gz: c0365d6efc7e71654d19f6a80fd17004d2a724fb09f2eb4dc0f3e2e7dedc1a36
5
5
  SHA512:
6
- metadata.gz: e86251a810ba452ed36ee67fde2ee8891625e9c3e79109f9f5eed0ad02c6c9937ebc0ed24952429df362458b5170c070081cff8256eba37c5350ba5b3adf538a
7
- data.tar.gz: 7cb0e3ed64582a667de99b58a4ab63be54cce5447828c9d0cf03361fabe421fa37d729669e49b17386c2aac86617dfbe32869f894b4858b56953ed85dd197b44
6
+ metadata.gz: 017d448d6431190a8b15deb81cfd0d507c5911aaba8481a625a684d2fc1f9af334fe7cbc82bc361422b62131346da28e7ddf796af1ffb03f17448d676936cd06
7
+ data.tar.gz: 468d32049f3a229cf3f6e1b0c728cfd51126ceadea09b20042208e537ea94bc80d8216e1953d4d43675037e59472fe6422077256d9fc971d4379ce0da2682b36
@@ -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
+ [![Gem Version](https://badge.fury.io/rb/active_interaction-active_job.svg)](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
- # This creates Add::Job class
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.13"
29
- spec.add_development_dependency "rake", "~> 10.0"
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
- def run *args
9
- @job_class.new(@service_class.name, *args).enqueue @options
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(default_job_class))
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.const_set(:Job, Class.new(job_class))
22
+ subclass.define_job_class job_class
30
23
  end
31
24
 
32
- def set options = {}
33
- ActiveInteraction::ActiveJob::ConfiguredJob.new(job_class, self, options)
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 interaction_klass_name, *args
3
- interaction_klass_name.constantize.run!(*args)
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
@@ -1,5 +1,5 @@
1
1
  module ActiveInteraction
2
2
  module ActiveJob
3
- VERSION = "0.1.0"
3
+ VERSION = "0.3.2"
4
4
  end
5
5
  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.1.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: 2016-12-30 00:00:00.000000000 Z
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: '1.13'
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: '1.13'
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: '10.0'
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: '10.0'
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
- rubyforge_project:
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