operationable 0.2.4 → 0.2.5
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/lib/operationable.rb +2 -0
- data/lib/operationable/persister.rb +48 -0
- data/lib/operationable/runners/base.rb +6 -0
- data/lib/operationable/runners/separate.rb +10 -2
- data/lib/operationable/runners/serial.rb +13 -2
- data/lib/operationable/serializer.rb +7 -1
- data/lib/operationable/version.rb +1 -1
- metadata +4 -10
- data/operationable-0.1.7.gem +0 -0
- data/operationable-0.1.8.gem +0 -0
- data/operationable-0.1.9.gem +0 -0
- data/operationable-0.2.0.gem +0 -0
- data/operationable-0.2.1.gem +0 -0
- data/operationable-0.2.2.gem +0 -0
- data/operationable-0.2.3.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da4f2c001b58a3ce07d7d7a16100c9abdee28cd2
|
4
|
+
data.tar.gz: 52b9abff75acce3b938c60708e10646e79fb7a98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 907b157d42743139639ee5999ad221e25b576bb33a802078db1a9f18f5e3047502c4844f6957f1c41001168e7d518fac48265075aa1b475ba2bbcde17441e275
|
7
|
+
data.tar.gz: 19838de1878f31a759c11002d42ff0c1bd301f8a794e310cdd477965bcf81f0a05deb58714d76df99d7863627a2fe14911aefb748c533a1463d6f5a7f53b6882
|
data/lib/operationable.rb
CHANGED
@@ -8,6 +8,7 @@ require 'operationable/callback'
|
|
8
8
|
require 'operationable/operation'
|
9
9
|
require 'operationable/serializer'
|
10
10
|
require 'operationable/specification'
|
11
|
+
require 'operationable/persister'
|
11
12
|
|
12
13
|
require 'operationable/runners/base'
|
13
14
|
require 'operationable/runners/serial'
|
@@ -24,5 +25,6 @@ module Operationable
|
|
24
25
|
class Callback < ::Operationable::Callback; end
|
25
26
|
class Specification < ::Operationable::Specification; end
|
26
27
|
class Serializer < ::Operationable::Serializer; end
|
28
|
+
class Persister < ::Operationable::Persister; end
|
27
29
|
end
|
28
30
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Operationable
|
3
|
+
class Persister
|
4
|
+
class << self
|
5
|
+
def persist(callbacks, initiator_id, params, name)
|
6
|
+
::Operation.create(
|
7
|
+
callbacks: callbacks.map { |callback|
|
8
|
+
{
|
9
|
+
status: ::Operation::STATUS_INIT,
|
10
|
+
name: callback[:callback_method_name],
|
11
|
+
queue: callback[:queue]
|
12
|
+
}
|
13
|
+
},
|
14
|
+
initiator_id: initiator_id,
|
15
|
+
params: params,
|
16
|
+
name: name
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def working(id, name)
|
21
|
+
update(id, name, ::Operation::STATUS_WORKING)
|
22
|
+
end
|
23
|
+
|
24
|
+
def completed(id, name)
|
25
|
+
update(id, name, ::Operation::STATUS_COMPLETED)
|
26
|
+
end
|
27
|
+
|
28
|
+
def around_call(id, name, block)
|
29
|
+
working(id, name)
|
30
|
+
block.call
|
31
|
+
completed(id, name)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def update(id, name, status)
|
37
|
+
op = ::Operation.find(id)
|
38
|
+
callbacks = op.callbacks.map do |cb|
|
39
|
+
cb['status'] = status if cb['name'] === name
|
40
|
+
cb
|
41
|
+
end
|
42
|
+
|
43
|
+
op.callbacks = callbacks
|
44
|
+
op.save
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -12,6 +12,8 @@ module Operationable
|
|
12
12
|
@callbacks = []
|
13
13
|
|
14
14
|
initialize_callbacks
|
15
|
+
|
16
|
+
persist_operation
|
15
17
|
end
|
16
18
|
|
17
19
|
def run
|
@@ -19,6 +21,10 @@ module Operationable
|
|
19
21
|
|
20
22
|
private
|
21
23
|
|
24
|
+
def persist_operation
|
25
|
+
@persist_operation ||= ::Operationable::Persister.persist(check_callbacks, user.id, props, operation_class_name)
|
26
|
+
end
|
27
|
+
|
22
28
|
def props
|
23
29
|
serializer_instance.serialize
|
24
30
|
end
|
@@ -14,12 +14,20 @@ module Operationable
|
|
14
14
|
{ type: 'separate',
|
15
15
|
callback_class_name: callback_class_name,
|
16
16
|
callback_method_name: callback_method_name,
|
17
|
-
queue: queue
|
17
|
+
queue: queue,
|
18
|
+
op_id: persist_operation.id }
|
18
19
|
end
|
19
20
|
|
21
|
+
# def self.call(options, props)
|
22
|
+
# options[:callback_class_name].constantize.new(props).method(options[:callback_method_name]).call
|
23
|
+
# end
|
24
|
+
|
20
25
|
def self.call(options, props)
|
21
|
-
options[:
|
26
|
+
::Operationable::Persister.around_call(options[:op_id], options[:callback_method_name], -> {
|
27
|
+
options[:callback_class_name].constantize.new(props).method(options[:callback_method_name]).call
|
28
|
+
})
|
22
29
|
end
|
30
|
+
|
23
31
|
end
|
24
32
|
end
|
25
33
|
end
|
@@ -10,16 +10,27 @@ module Operationable
|
|
10
10
|
(queue.blank? ? self.class : OperationJob.method(perform_method)).call(options, props)
|
11
11
|
end
|
12
12
|
|
13
|
+
# def self.call(options, props)
|
14
|
+
# instance = options[:callback_class_name].constantize.new(props)
|
15
|
+
# options[:callback_names].each { |method_name| instance.method(method_name).call }
|
16
|
+
# end
|
17
|
+
|
13
18
|
def self.call(options, props)
|
14
19
|
instance = options[:callback_class_name].constantize.new(props)
|
15
|
-
|
20
|
+
|
21
|
+
options[:callback_names].each do |method_name|
|
22
|
+
::Operationable::Persister.around_call(options[:op_id], method_name, -> {
|
23
|
+
instance.method(method_name).call
|
24
|
+
})
|
25
|
+
end
|
16
26
|
end
|
17
27
|
|
18
28
|
def options
|
19
29
|
{ type: 'serial',
|
20
30
|
callback_class_name: callback_class_name,
|
21
31
|
callback_names: callback_names,
|
22
|
-
queue: queue
|
32
|
+
queue: queue,
|
33
|
+
op_id: persist_operation.id }
|
23
34
|
end
|
24
35
|
|
25
36
|
private
|
@@ -22,7 +22,13 @@ module Operationable
|
|
22
22
|
private
|
23
23
|
|
24
24
|
def extract_props(record, user)
|
25
|
-
{
|
25
|
+
{
|
26
|
+
**extract_from_record(record),
|
27
|
+
**extract_from_user(user),
|
28
|
+
params: params,
|
29
|
+
activity: activity,
|
30
|
+
action_name: action_name
|
31
|
+
}
|
26
32
|
end
|
27
33
|
|
28
34
|
def extract_from_record(record)
|
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.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kirill Suhodolov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-03-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activejob
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- lib/operationable/builder.rb
|
91
91
|
- lib/operationable/callback.rb
|
92
92
|
- lib/operationable/operation.rb
|
93
|
+
- lib/operationable/persister.rb
|
93
94
|
- lib/operationable/runners/base.rb
|
94
95
|
- lib/operationable/runners/separate.rb
|
95
96
|
- lib/operationable/runners/serial.rb
|
@@ -99,13 +100,6 @@ files:
|
|
99
100
|
- lib/operations/create.rb
|
100
101
|
- lib/operations/destroy.rb
|
101
102
|
- lib/operations/update.rb
|
102
|
-
- operationable-0.1.7.gem
|
103
|
-
- operationable-0.1.8.gem
|
104
|
-
- operationable-0.1.9.gem
|
105
|
-
- operationable-0.2.0.gem
|
106
|
-
- operationable-0.2.1.gem
|
107
|
-
- operationable-0.2.2.gem
|
108
|
-
- operationable-0.2.3.gem
|
109
103
|
- operationable.gemspec
|
110
104
|
- spec/operationable_spec.rb
|
111
105
|
- spec/spec_helper.rb
|
@@ -129,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
123
|
version: '0'
|
130
124
|
requirements: []
|
131
125
|
rubyforge_project:
|
132
|
-
rubygems_version: 2.
|
126
|
+
rubygems_version: 2.6.10
|
133
127
|
signing_key:
|
134
128
|
specification_version: 4
|
135
129
|
summary: Implementation of command pattern to avoid ActiveRecord callbacks and get
|
data/operationable-0.1.7.gem
DELETED
Binary file
|
data/operationable-0.1.8.gem
DELETED
Binary file
|
data/operationable-0.1.9.gem
DELETED
Binary file
|
data/operationable-0.2.0.gem
DELETED
Binary file
|
data/operationable-0.2.1.gem
DELETED
Binary file
|
data/operationable-0.2.2.gem
DELETED
Binary file
|
data/operationable-0.2.3.gem
DELETED
Binary file
|