operationable 0.5.5 → 0.5.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6edf66c7b75e60f58aa296b89200a5e19d19628c0b8d80b54369fb40cf5f232c
4
- data.tar.gz: 60ac229144e1f919746746e86d7cdd373cb6aa619c81d650e13c64e8f3874a1f
3
+ metadata.gz: 040e59f59c21f9ef4173c7c6a8b92361b0322a0c8665050025fca4d31928601d
4
+ data.tar.gz: 9452b615efa14ab19318a586d1b28fb3f4c2e9a3bb9d72993242cde7ae2f0ce4
5
5
  SHA512:
6
- metadata.gz: 8f52d31a1f5e413efa3155071943b2eaf6a13c49bb3e12b5241969da6f90cec8434a14d32d4de3f693f4ef8c9f5343585e9450e1c9c78d62e12244072e5b0af5
7
- data.tar.gz: 835fde7f0528eb95ec8bb3faf09844e2b8ae6134796676b40a89a643b103bdb01daa3c7b9e75a742e1b65c7470005d5ad2afab055472cb9cbd1cc14d79e141be
6
+ metadata.gz: 31144ef82aad7945a9a1b8a7fb749c1e0130d5fe3a0a78e3da76781f3cc42a699a6448ea8293d23e335212588f4e349243fee4b2c9cd66e8ff4055ce77b88040
7
+ data.tar.gz: ebd984eca0102f0883037087308580ad098607319e046c27c2389a27a50099f7e81143d23c7b8db70c51a1ed87bf0a0fceab9eb25700c13fa033341921456eb6
data/README.md CHANGED
@@ -59,11 +59,23 @@ module EntityOperation
59
59
  end
60
60
  end
61
61
 
62
+ class Delayer < Operationable::Delayer
63
+ def delay_callback_one
64
+ { wait_until: Date.tomorrow.noon } # or wait
65
+ end
66
+ end
67
+
62
68
  class Runner < Operationable::Runners::Separate
63
69
  def initialize_callbacks
64
70
  push_to_queue(:callback_one)
65
- push_to_queue(:callback_two, :low)
66
- push_to_queue(:callback_three, :high)
71
+ push_to_queue(:callback_two, queue: :low)
72
+ push_to_queue(:callback_three, queue: :high, job_class_name: MySpecialJob)
73
+ push_to_queue(:callback_four, queue: :high, params: {hello: 123})
74
+ end
75
+
76
+ # This is default behaviour, but you can redefine it, to use with other adapter for example
77
+ def perform(job_class_name, args, delayed_params)
78
+ job_class_name.to_s.constantize.set(delayed_params).method(perform_method).call(args)
67
79
  end
68
80
  end
69
81
 
@@ -101,6 +113,10 @@ push_to_queue(callback_name, queue_name) if queue_name not passed, callback will
101
113
 
102
114
  Operations work via ActiveJob, so you can use any adapter that you want.
103
115
 
116
+ ### Delayer
117
+
118
+ This class process when process job
119
+
104
120
  ### Job
105
121
 
106
122
  I get rid of ActiveJob dependency. So, extend you exting job class with code below
@@ -118,7 +134,7 @@ end
118
134
 
119
135
  ```
120
136
 
121
- Define job class name at your initializers (config/initializers/operationable.rb)
137
+ Define global job class name at your initializers (config/initializers/operationable.rb)
122
138
 
123
139
  ```ruby
124
140
  module Operationable
@@ -127,18 +143,11 @@ module Operationable
127
143
  def job_class
128
144
  'OpJob'
129
145
  end
130
-
131
- # This is default behaviour, but you can redefine it, to use with other adapter
132
- def perform(job_class_name, args)
133
- job_class_name.to_s.constantize.method(perform_method).call(args)
134
- end
135
146
  end
136
147
  end
137
148
  end
138
149
  ```
139
150
 
140
-
141
-
142
151
  ### Serializer
143
152
 
144
153
  Serializer used to define what values should be passed to job(redis do not accept AR instances or other complex structures).
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ module Operationable
3
+ class Delayer
4
+ attr_reader :record, :user, :params, :activity, :action_name
5
+
6
+ def initialize(record, user, params={}, activity='', action_name='')
7
+ @record = record
8
+ @user = user
9
+ @params = params
10
+ @activity = activity
11
+ @action_name = action_name
12
+ end
13
+ end
14
+ end
@@ -54,8 +54,8 @@ module Operationable
54
54
  def initialize_callbacks
55
55
  end
56
56
 
57
- def push_to_queue(*callback_method_names, queue: nil, params: {})
58
- callback_method_names.each do |callback_method_name, job_class_name|
57
+ def push_to_queue(*callback_method_names, job_class_name: nil, queue: nil, params: {})
58
+ callback_method_names.each do |callback_method_name|
59
59
  callbacks << {
60
60
  callback_method_name: callback_method_name.to_s,
61
61
  job_class_name: job_class_name.nil? ? job_class.to_s : job_class_name.to_s,
@@ -65,10 +65,6 @@ module Operationable
65
65
  end
66
66
  end
67
67
 
68
- def callback_names
69
- check_callbacks.map { |callback| callback[:callback_method_name] }
70
- end
71
-
72
68
  def check_callbacks
73
69
  callbacks.find_all do |callback|
74
70
  satisfy = specification&.try("should_#{callback[:callback_method_name]}".to_sym)
@@ -77,7 +73,11 @@ module Operationable
77
73
  end
78
74
 
79
75
  def serializer_instance
80
- serializer_class_name.constantize.new(record, user, params, result, activity, action_name)
76
+ @serializer_instance ||= serializer_class_name.constantize.new(record, user, params, result, activity, action_name)
77
+ end
78
+
79
+ def delayer
80
+ @delayer ||= delayer_class_name.constantize.new(record, user, params, result, activity, action_name)
81
81
  end
82
82
 
83
83
  def specification
@@ -96,6 +96,10 @@ module Operationable
96
96
  "#{operation_class_name}::Specification"
97
97
  end
98
98
 
99
+ def delayer_class_name
100
+ "#{operation_class_name}::Delayer"
101
+ end
102
+
99
103
  def operation_class_name
100
104
  self.class.name.chomp('::Runner')
101
105
  end
@@ -116,8 +120,8 @@ module Operationable
116
120
  sync? ? job_sync_execute_method : job_async_execute_method
117
121
  end
118
122
 
119
- def perform(job_class_name, args)
120
- job_class_name.to_s.constantize.method(perform_method).call(args)
123
+ def perform(job_class_name, args, delayed_params)
124
+ job_class_name.to_s.constantize.set(delayed_params).method(perform_method).call(args)
121
125
  end
122
126
 
123
127
  def sync?
@@ -15,7 +15,12 @@ module Operationable
15
15
  props: props.merge(params)
16
16
  }
17
17
 
18
- queue.blank? ? self.class.call(args) : perform(job_class_name, args)
18
+ queue.blank? ? self.class.call(args) : perform(job_class_name, args, get_delayed_params(callback_method_name))
19
+ end
20
+
21
+ def get_delayed_params(callback_method_name)
22
+ delay = delayer&.try("delay_#{callback_method_name}".to_sym)
23
+ delay.nil? ? {} : delay
19
24
  end
20
25
 
21
26
  def q_options(callback_method_name, queue)
@@ -26,6 +26,10 @@ module Operationable
26
26
  queue: queue })
27
27
  end
28
28
 
29
+ def callback_names
30
+ check_callbacks.map { |callback| callback[:callback_method_name] }
31
+ end
32
+
29
33
  private
30
34
 
31
35
  def queue
@@ -1,3 +1,3 @@
1
1
  module Operationable
2
- VERSION = "0.5.5"
2
+ VERSION = "0.5.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: operationable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Suhodolov
@@ -74,6 +74,7 @@ files:
74
74
  - lib/operationable.rb
75
75
  - lib/operationable/builder.rb
76
76
  - lib/operationable/callback.rb
77
+ - lib/operationable/delayer.rb
77
78
  - lib/operationable/operation.rb
78
79
  - lib/operationable/runners/base.rb
79
80
  - lib/operationable/runners/separate.rb