operationable 0.5.2 → 0.5.7
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 +4 -4
- data/README.md +49 -2
- data/lib/operationable.rb +1 -2
- data/lib/operationable/delayer.rb +14 -0
- data/lib/operationable/runners/base.rb +13 -9
- data/lib/operationable/runners/separate.rb +6 -1
- data/lib/operationable/runners/serial.rb +4 -0
- data/lib/operationable/version.rb +1 -1
- data/operationable.gemspec +1 -1
- metadata +2 -16
- data/lib/jobs/operation_job.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fbdd9d9c8fb493193125b3a501168a1c765781ed20aea3be5fd4cb6f7edf7d5
|
4
|
+
data.tar.gz: 8d9a22e9f045117ec296cc6703001a7fc0ac845017bf471361f499f3ac1a4aa0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 109e26d17c6ee60b021db6b2bff48cb13c1d1b741a2e5e3b62c4cd07c77af95247286df8f4ca88c722a8dc7defee8f6b93f27a3f1b3e1cb2509f6c39b8907eeb
|
7
|
+
data.tar.gz: c415f2f9a09f081337ab2325517206c6a31808748b9f6f532fd4fc4eeb86710deaf38004715d454579746b35a685aea7d42e49e885c0b580bf528e3ea8cabe95
|
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,41 @@ 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
|
+
|
120
|
+
### Job
|
121
|
+
|
122
|
+
I get rid of ActiveJob dependency. So, extend you exting job class with code below
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
class OpJob < ActiveJob::Base
|
126
|
+
queue_as do
|
127
|
+
arguments.first[:q_options][:queue]
|
128
|
+
end
|
129
|
+
|
130
|
+
def perform(q_options:, props:)
|
131
|
+
"Operationable::Runners::#{q_options[:type].capitalize}".constantize.call(q_options: q_options, props: props)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
```
|
136
|
+
|
137
|
+
Define global job class name at your initializers (config/initializers/operationable.rb)
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
module Operationable
|
141
|
+
module Runners
|
142
|
+
class Base
|
143
|
+
def job_class
|
144
|
+
'OpJob'
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
```
|
150
|
+
|
104
151
|
### Serializer
|
105
152
|
|
106
153
|
Serializer used to define what values should be passed to job(redis do not accept AR instances or other complex structures).
|
data/lib/operationable.rb
CHANGED
@@ -9,13 +9,12 @@ require 'operationable/callback'
|
|
9
9
|
require 'operationable/operation'
|
10
10
|
require 'operationable/serializer'
|
11
11
|
require 'operationable/specification'
|
12
|
+
require 'operationable/delayer'
|
12
13
|
|
13
14
|
require 'operationable/runners/base'
|
14
15
|
require 'operationable/runners/serial'
|
15
16
|
require 'operationable/runners/separate'
|
16
17
|
|
17
|
-
require 'jobs/operation_job'
|
18
|
-
|
19
18
|
require 'operations/create'
|
20
19
|
require 'operations/destroy'
|
21
20
|
require 'operations/update'
|
@@ -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
|
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)
|
data/operationable.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.required_ruby_version = '>= 2.1.0'
|
24
24
|
|
25
|
-
spec.add_dependency 'activejob', '>= 4.2.0'
|
25
|
+
# spec.add_dependency 'activejob', '>= 4.2.0'
|
26
26
|
|
27
27
|
spec.add_development_dependency "bundler", "~> 1.13"
|
28
28
|
spec.add_development_dependency "rake", "~> 10.0"
|
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.
|
4
|
+
version: 0.5.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kirill Suhodolov
|
@@ -11,20 +11,6 @@ bindir: bin
|
|
11
11
|
cert_chain: []
|
12
12
|
date: 2020-12-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: activejob
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - ">="
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: 4.2.0
|
21
|
-
type: :runtime
|
22
|
-
prerelease: false
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - ">="
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: 4.2.0
|
28
14
|
- !ruby/object:Gem::Dependency
|
29
15
|
name: bundler
|
30
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -85,10 +71,10 @@ files:
|
|
85
71
|
- Rakefile
|
86
72
|
- bin/console
|
87
73
|
- bin/setup
|
88
|
-
- lib/jobs/operation_job.rb
|
89
74
|
- lib/operationable.rb
|
90
75
|
- lib/operationable/builder.rb
|
91
76
|
- lib/operationable/callback.rb
|
77
|
+
- lib/operationable/delayer.rb
|
92
78
|
- lib/operationable/operation.rb
|
93
79
|
- lib/operationable/runners/base.rb
|
94
80
|
- lib/operationable/runners/separate.rb
|
data/lib/jobs/operation_job.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
class OperationJob < ActiveJob::Base
|
3
|
-
queue_as do
|
4
|
-
arguments.first[:q_options][:queue]
|
5
|
-
end
|
6
|
-
|
7
|
-
def perform(q_options:, props:)
|
8
|
-
"Operationable::Runners::#{q_options[:type].capitalize}".constantize.call(q_options: q_options, props: props)
|
9
|
-
end
|
10
|
-
end
|