say_when 2.1.1 → 2.2.0
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
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6a15986d3be49bd5a4df5bfba2efb10a6e87bb385dae3db7302a26998f6cc784
|
4
|
+
data.tar.gz: fd26b203f07e779d0f663c0650efe525f337ceb3567fdcc73aa8512bca42247f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25b2394bb39c4ed8fcd0955ecc17dba6c1c45caabfb5b3c0703e58f941adc7661356c2a103a315d5baa740fa6142ac6519eacda35ac062b9f4498607de9eeef4
|
7
|
+
data.tar.gz: 128ca1ff31b19f594075e1a671f321f8f62aad440d2708afeb6d727179b6909eaac085acbcac6129c7e5f2f3e59632b167577699aefacd0f5d87b38a86f554cc
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'concurrent'
|
4
2
|
require 'logger'
|
5
3
|
require 'say_when/poller/base_poller'
|
@@ -11,20 +9,19 @@ module SayWhen
|
|
11
9
|
|
12
10
|
def initialize(tick = nil)
|
13
11
|
@tick_length = tick.to_i if tick
|
14
|
-
start
|
15
12
|
end
|
16
13
|
|
17
14
|
def start
|
18
|
-
@tick_timer
|
15
|
+
@tick_timer ||= Concurrent::TimerTask.new(execution_interval: tick_length) do
|
19
16
|
process_jobs
|
20
17
|
end.tap(&:execute)
|
21
18
|
end
|
22
19
|
|
23
20
|
def stop
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
return unless @tick_timer
|
22
|
+
|
23
|
+
@tick_timer.shutdown
|
24
|
+
@tick_timer = nil
|
28
25
|
end
|
29
26
|
end
|
30
27
|
end
|
@@ -48,13 +48,13 @@ module SayWhen
|
|
48
48
|
serialize :data
|
49
49
|
|
50
50
|
belongs_to :scheduled, polymorphic: true
|
51
|
-
has_many
|
51
|
+
has_many :job_executions, class_name: 'SayWhen::Storage::ActiveRecordStrategy::JobExecution'
|
52
52
|
|
53
53
|
before_create :set_defaults
|
54
54
|
|
55
55
|
def self.job_create(job)
|
56
56
|
if existing_job = find_named_job(job[:group], job[:name])
|
57
|
-
existing_job.tap { |j| j.
|
57
|
+
existing_job.tap { |j| j.update(job) }
|
58
58
|
else
|
59
59
|
create(job)
|
60
60
|
end
|
@@ -71,15 +71,15 @@ module SayWhen
|
|
71
71
|
check_connection
|
72
72
|
hide_logging do
|
73
73
|
SayWhen::Storage::ActiveRecordStrategy::Job.transaction do
|
74
|
-
# select and lock the next job that needs
|
75
|
-
next_job = where(status: STATE_WAITING)
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
74
|
+
# select and lock the next job that needs executing (status waiting, and after no_later_than)
|
75
|
+
next_job = where(status: STATE_WAITING)
|
76
|
+
.where('next_fire_at < ?', no_later_than)
|
77
|
+
.order(next_fire_at: 'asc')
|
78
|
+
.lock(true)
|
79
|
+
.first
|
80
80
|
|
81
81
|
# set status to acquired to take it out of rotation
|
82
|
-
next_job
|
82
|
+
next_job&.update_attribute(:status, STATE_ACQUIRED)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
next_job
|
@@ -87,8 +87,9 @@ module SayWhen
|
|
87
87
|
|
88
88
|
def self.reset_acquired(older_than_seconds)
|
89
89
|
return unless older_than_seconds.to_i > 0
|
90
|
+
|
90
91
|
older_than = (Time.now - older_than_seconds.to_i)
|
91
|
-
where('status = ? and updated_at < ?', STATE_ACQUIRED, older_than).update_all(
|
92
|
+
where('status = ? and updated_at < ?', STATE_ACQUIRED, older_than).update_all(status: STATE_WAITING)
|
92
93
|
end
|
93
94
|
|
94
95
|
def self.check_connection
|
@@ -100,10 +101,10 @@ module SayWhen
|
|
100
101
|
end
|
101
102
|
|
102
103
|
def self.hide_logging
|
103
|
-
|
104
|
+
@_null_logger ||= Logger.new(IO::NULL)
|
105
|
+
old_logger = ::ActiveRecord::Base.logger
|
104
106
|
begin
|
105
|
-
|
106
|
-
::ActiveRecord::Base.logger = nil
|
107
|
+
::ActiveRecord::Base.logger = @_null_logger
|
107
108
|
yield
|
108
109
|
ensure
|
109
110
|
::ActiveRecord::Base.logger = old_logger
|
@@ -112,21 +113,21 @@ module SayWhen
|
|
112
113
|
|
113
114
|
def set_defaults
|
114
115
|
self.status = STATE_WAITING
|
115
|
-
self.next_fire_at =
|
116
|
+
self.next_fire_at = trigger.next_fire_at
|
116
117
|
end
|
117
118
|
|
118
|
-
def fired(fired_at=Time.now)
|
119
|
-
self.class.transaction
|
119
|
+
def fired(fired_at = Time.now)
|
120
|
+
self.class.transaction do
|
120
121
|
super
|
121
|
-
|
122
|
-
|
122
|
+
save!
|
123
|
+
end
|
123
124
|
end
|
124
125
|
|
125
126
|
def release
|
126
|
-
self.class.transaction
|
127
|
+
self.class.transaction do
|
127
128
|
super
|
128
|
-
|
129
|
-
|
129
|
+
save!
|
130
|
+
end
|
130
131
|
end
|
131
132
|
|
132
133
|
# default impl with some error handling and result recording
|
@@ -136,11 +137,11 @@ module SayWhen
|
|
136
137
|
result = execute_with_stored_result
|
137
138
|
else
|
138
139
|
begin
|
139
|
-
result =
|
140
|
-
SayWhen.logger.info("complete - job: #{
|
141
|
-
rescue Object =>
|
142
|
-
result = "#{
|
143
|
-
SayWhen.logger.error("error - job: #{
|
140
|
+
result = execute_job(data)
|
141
|
+
SayWhen.logger.info("complete - job: #{inspect}, result: #{result}")
|
142
|
+
rescue Object => e
|
143
|
+
result = "#{e.class.name}: #{e.message}\n\t#{e.backtrace.join("\n\t")}"
|
144
|
+
SayWhen.logger.error("error - job: #{inspect}, exception: #{result}")
|
144
145
|
end
|
145
146
|
end
|
146
147
|
result
|
@@ -150,10 +151,10 @@ module SayWhen
|
|
150
151
|
execution = JobExecution.create(job: self, status: STATE_EXECUTING, start_at: Time.now)
|
151
152
|
|
152
153
|
begin
|
153
|
-
execution.result =
|
154
|
+
execution.result = execute_job(data)
|
154
155
|
execution.status = 'complete'
|
155
|
-
rescue Object =>
|
156
|
-
execution.result = "#{
|
156
|
+
rescue Object => e
|
157
|
+
execution.result = "#{e.class.name}: #{e.message}\n\t#{e.backtrace.join("\n\t")}"
|
157
158
|
execution.status = 'error'
|
158
159
|
end
|
159
160
|
|
@@ -164,7 +165,7 @@ module SayWhen
|
|
164
165
|
end
|
165
166
|
end
|
166
167
|
|
167
|
-
module Acts
|
168
|
+
module Acts # :nodoc:
|
168
169
|
extend ActiveSupport::Concern
|
169
170
|
|
170
171
|
module ClassMethods
|
@@ -172,9 +173,9 @@ module SayWhen
|
|
172
173
|
include SayWhen::Storage::ActiveRecordStrategy::Acts::InstanceMethods
|
173
174
|
|
174
175
|
has_many :scheduled_jobs,
|
175
|
-
|
176
|
-
|
177
|
-
|
176
|
+
as: :scheduled,
|
177
|
+
class_name: 'SayWhen::Storage::ActiveRecordStrategy::Job',
|
178
|
+
dependent: :destroy
|
178
179
|
end
|
179
180
|
end
|
180
181
|
|
@@ -214,6 +215,4 @@ module SayWhen
|
|
214
215
|
end
|
215
216
|
|
216
217
|
aas = SayWhen::Storage::ActiveRecordStrategy::Acts
|
217
|
-
unless ActiveRecord::Base.include?(aas)
|
218
|
-
ActiveRecord::Base.send(:include, aas)
|
219
|
-
end
|
218
|
+
ActiveRecord::Base.send(:include, aas) unless ActiveRecord::Base.include?(aas)
|
data/lib/say_when/version.rb
CHANGED
@@ -85,7 +85,7 @@ describe SayWhen::Storage::ActiveRecordStrategy do
|
|
85
85
|
it 'resets acquired jobs' do
|
86
86
|
old = 2.hours.ago
|
87
87
|
j = strategy.create(valid_attributes)
|
88
|
-
j.
|
88
|
+
j.update(status: 'acquired', updated_at: old, created_at: old)
|
89
89
|
|
90
90
|
j.status.must_equal 'acquired'
|
91
91
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: say_when
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kuklewicz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -270,8 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
270
270
|
- !ruby/object:Gem::Version
|
271
271
|
version: '0'
|
272
272
|
requirements: []
|
273
|
-
|
274
|
-
rubygems_version: 2.5.1
|
273
|
+
rubygems_version: 3.1.4
|
275
274
|
signing_key:
|
276
275
|
specification_version: 4
|
277
276
|
summary: Scheduling system for programmatically defined and stored jobs.
|