operationable 0.5.3 → 0.5.8

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: 91bbd789046a4a209af2f97ec1334a943062b8b35d25e15a1a7dbe4383d67740
4
- data.tar.gz: 5870ada65a65e8fc32d445d671585ae8758bac55b6048db07cda8fc560cd4b1d
3
+ metadata.gz: b4e8fb2869237f5b4659aec5a8249112f34385a20f6d28366fa1e77d734a13ea
4
+ data.tar.gz: a9ce3ee3d30dbbf0bfe1cc8ba8fc12f1def3177a1edaa12435ab0e95710636c9
5
5
  SHA512:
6
- metadata.gz: 1a8a5e93c0104de1f1aa50d6fc5d42bbc2cca845e2b85f1a3e1e66ce34b09590ab68c6eff5af1458039377c89d95f18fb06fe8ba659fec79a3e38af96f6caa5b
7
- data.tar.gz: c8cfd9ba6ff3a6d0daaa42a8779028b3966d0159e334952cbe72c47488570c691893366a2bda15f9ae0e93cbabbdf398a42786af06e1d4351cbcddf0c9c9f93c
6
+ metadata.gz: 27aa66d3e45608c1e27934b12aa8bb290f76606703480e3770d72e2d5d05c299f7ac1f430a56fea9a6c1d108ce3d50941c05f2fd4360796bc3b4c09d6416b4dd
7
+ data.tar.gz: 635f36ae4ac796175c9a8c48d7b7db7fd63071788178307ea4a86839339a81220ec94290df5a656e0e4aa850c2c381cfec215b783b36d129571d8175cb7e9e20
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).
@@ -9,14 +9,12 @@ require 'operationable/callback'
9
9
  require 'operationable/operation'
10
10
  require 'operationable/serializer'
11
11
  require 'operationable/specification'
12
- require 'operationable/operationable_job'
12
+ require 'operationable/delayer'
13
13
 
14
14
  require 'operationable/runners/base'
15
15
  require 'operationable/runners/serial'
16
16
  require 'operationable/runners/separate'
17
17
 
18
- require 'jobs/operation_job'
19
-
20
18
  require 'operations/create'
21
19
  require 'operations/destroy'
22
20
  require 'operations/update'
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ module Operationable
3
+ class Delayer
4
+ attr_reader :record, :user, :params, :result, :activity, :action_name
5
+
6
+ def initialize(record, user, params={}, result=nil, activity='', action_name='')
7
+ @record = record
8
+ @user = user
9
+ @params = params
10
+ @result = result
11
+ @activity = activity
12
+ @action_name = action_name
13
+ end
14
+ end
15
+ 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,11 +73,15 @@ 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
84
- @specification ||= specification_class_name.constantize.new(record, user, params, activity, action_name)
84
+ @specification ||= specification_class_name.constantize.new(record, user, params, result, activity, action_name)
85
85
  end
86
86
 
87
87
  def callback_class_name
@@ -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,12 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
  module Operationable
3
3
  class Specification
4
- attr_reader :record, :user, :params, :activity, :action_name
4
+ attr_reader :record, :user, :params, :result, :activity, :action_name
5
5
 
6
- def initialize(record, user, params={}, activity='', action_name='')
6
+ def initialize(record, user, params={}, result=nil, activity='', action_name='')
7
7
  @record = record
8
8
  @user = user
9
9
  @params = params
10
+ @result = result
10
11
  @activity = activity
11
12
  @action_name = action_name
12
13
  end
@@ -1,3 +1,3 @@
1
1
  module Operationable
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.8"
3
3
  end
@@ -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.3
4
+ version: 0.5.8
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
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
- # TODO: use module instead
3
- class OperationJob < ActiveJob::Base
4
- queue_as do
5
- arguments.first[:q_options][:queue]
6
- end
7
-
8
- def perform(q_options:, props:)
9
- "Operationable::Runners::#{q_options[:type].capitalize}".constantize.call(q_options: q_options, props: props)
10
- end
11
- end