ruby-clock 2.0.0.beta2 → 2.0.0.beta3

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
2
  SHA256:
3
- metadata.gz: 9fdfa3656f0ffbdf60b162a594809e29e9f0579cf3f5f52e98ffd857a811c348
4
- data.tar.gz: f63dd579f2cd258f89f17666338ec9d433a63e2b93d0a400975ee6c1e61886fa
3
+ metadata.gz: 17d680fbe8df5efadea1cfa9123682fd2557828515fabfafad6825476669b368
4
+ data.tar.gz: d68673fdc64e3985a170d129b6642b00f323256904e4e54c07660bf1d73cd4e3
5
5
  SHA512:
6
- metadata.gz: 938ec658ba3837be8a90c49fdd8d2d6a050b1b6a19486bc2b10479e81370ed3fe5c0e4501293b02a2c8efcfe82d67974e887c2069270986f3398b89762c04707
7
- data.tar.gz: c3376b79456a66c2b3c1eb5492b9a0429e69ece7b5207a73d2792c8830c33355c14dc622c2a37e8b6b8e2b9b27cdaaa4d0c83449e6e9c8aca3ae2538e2a90af0
6
+ metadata.gz: 789d4ba0e97036cf12473ba5d0c6b190ce164e81573738c3f284910fb6de39fb13ae9a1e3342d6c621ede962b105923a05cc7c226c0294aea26dbb3d160c64f8
7
+ data.tar.gz: 381e0a04c4d0dc0425176d8414939658b669caaa0b1f2c2253c511506800ce01788eac2f4ef8cac9ebbdaac31031171917a8fac1965b4f3098f8f8c7a5b2cc8d
data/CHANGELOG.md CHANGED
@@ -7,9 +7,13 @@
7
7
  * Code reorganization so there are no unnecessary methods in top-level Kernel namespace
8
8
  * DSL methods are now at the top-level namespace (`schedule.every` → `every`, `schedule.cron` → `cron`)
9
9
  * error handler definition is now at the top-level namespace (`def schedule.on_error` → `on_error do`)
10
+ * around callbacks now have a top-level namespace method, which is different from the above in that...
11
+ * multiple around callbacks can be consecutively assigned
10
12
 
11
13
  ### Migrating from ruby-clock version 1 to version 2
12
14
 
15
+ * if you have and existing `def schedule.around_trigger`, you will need to change it to use the new
16
+ `around_action` method. see readme.
13
17
  * There is no longer a need to have a binstub in rails. You can delete bin/clock from your app.
14
18
  * The invocations (in Procfile, or wherever else you start ruby-clock) should change from
15
19
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- THESE ARE THE DOCS FOR VERSION 2.0.0.beta2
1
+ THESE ARE THE DOCS FOR VERSION 2.0.0.beta
2
2
 
3
3
  See version 1 docs here: https://github.com/jjb/ruby-clock/tree/v1.0.0
4
4
 
@@ -152,7 +152,43 @@ end
152
152
 
153
153
  ### Callbacks
154
154
 
155
- You can define before, after, and around callbacks which will run for all jobs.
155
+ You can define around callbacks which will run for all jobs, like shown below.
156
+ This somewhat awkward syntax is necessary in order to enable the ability to define multiple callbacks.
157
+ (perhaps in different files, shared by multiple Clockfiles, etc.).
158
+
159
+ ```ruby
160
+ around_action do |job_proc, job_info|
161
+ puts "before1 #{job_info.class}"
162
+ job_proc.call
163
+ puts "after1"
164
+ end
165
+
166
+ around_action do |job_proc|
167
+ puts "before2"
168
+ job_proc.call
169
+ puts "after2"
170
+ end
171
+
172
+ every('2 seconds') do
173
+ puts "hello from a ruby-clock job"
174
+ end
175
+ ```
176
+
177
+
178
+ ```
179
+ before1 Rufus::Scheduler::EveryJob
180
+ before2
181
+ hello from a ruby-clock job
182
+ after2
183
+ after1
184
+ ```
185
+
186
+ The around callbacks code will be run in the individual job thread.
187
+
188
+ rufus-scheduler also provides before and after hooks. ruby-clock does not provide convenience methods for these
189
+ but you can easily use them via the `schedule` object. These will run in the outer scheduling thread and not in
190
+ the job thread, so they may have slightly different behavior in some cases. There is likely no reason to use them
191
+ instead of `around_action`.
156
192
  Read [the rufus-scheduler documentation](https://github.com/jmettraux/rufus-scheduler/#callbacks)
157
193
  to learn how to do this. Where the documentation references `s`, you should use `schedule`.
158
194
 
@@ -1,5 +1,26 @@
1
1
  on_error do |job, error|
2
- raise error
2
+ puts "An error has occurred with job #{job.identifier}: #{error.class}: #{error.message}"
3
+ end
4
+ # on_error do |job, error|
5
+ # raise error
6
+ # end
7
+
8
+ around_action do |job_proc, job_info|
9
+ puts "before1 #{job_info.class}"
10
+ job_proc.call
11
+ puts "after1"
12
+ end
13
+
14
+ around_action do |job_proc|
15
+ puts "before2"
16
+ job_proc.call
17
+ puts "after2"
18
+ end
19
+
20
+ around_action do |job_proc, job_info|
21
+ puts "before3 #{job_info.class}"
22
+ job_proc.call
23
+ puts "after3"
3
24
  end
4
25
 
5
26
  every('2 seconds') do
@@ -10,6 +31,10 @@ every('2 seconds') do
10
31
  shell 'say hello'
11
32
  end
12
33
 
34
+ every('2 seconds') do
35
+ raise "An error."
36
+ end
37
+
13
38
  cron('*/10 * * * * *') do
14
39
  puts "cron running on every 10th second #{Time.now}"
15
40
  end
@@ -1,31 +1,32 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- ruby-clock (0.8.0.rc3)
4
+ ruby-clock (2.0.0.beta2)
5
5
  method_source
6
6
  rufus-scheduler (~> 3.8)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- concurrent-ruby (1.1.9)
12
- et-orbi (1.2.5)
11
+ concurrent-ruby (1.1.10)
12
+ et-orbi (1.2.7)
13
13
  tzinfo
14
- fugit (1.5.2)
15
- et-orbi (~> 1.1, >= 1.1.8)
14
+ fugit (1.7.1)
15
+ et-orbi (~> 1, >= 1.2.7)
16
16
  raabro (~> 1.4)
17
17
  method_source (1.0.0)
18
18
  raabro (1.4.0)
19
- rufus-scheduler (3.8.0)
19
+ rufus-scheduler (3.8.2)
20
20
  fugit (~> 1.1, >= 1.1.6)
21
- tzinfo (2.0.4)
21
+ tzinfo (2.0.5)
22
22
  concurrent-ruby (~> 1.0)
23
23
 
24
24
  PLATFORMS
25
25
  arm64-darwin-20
26
+ arm64-darwin-21
26
27
 
27
28
  DEPENDENCIES
28
29
  ruby-clock!
29
30
 
30
31
  BUNDLED WITH
31
- 2.2.28
32
+ 2.3.8
@@ -1,23 +1,5 @@
1
- on_error do |job, error|
2
- puts "An error has occurred: #{error.class}: #{error.message}"
3
- end
4
-
5
- every('2 seconds') do
6
- puts "hello from a ruby-clock job"
7
- end
8
-
9
- every('2 seconds') do
10
- shell 'say hello'
11
- end
1
+ load '../example-app/Clockfile'
12
2
 
13
3
  every('2 seconds') do
14
4
  puts Example.count
15
5
  end
16
-
17
- every('2 seconds') do
18
- raise "An error."
19
- end
20
-
21
- cron('*/10 * * * * *') do
22
- puts "cron running on every 10th second #{Time.now}"
23
- end
data/exe/clock CHANGED
@@ -41,6 +41,10 @@ def on_error(&on_error_block)
41
41
  end
42
42
  end
43
43
 
44
+ def around_action(&b)
45
+ RubyClock.instance.around_actions << b
46
+ end
47
+
44
48
  def cron(...)
45
49
  RubyClock.instance.schedule.cron(...)
46
50
  end
@@ -58,12 +62,9 @@ end
58
62
  load ARGV[0] || 'Clockfile'
59
63
 
60
64
  if defined?(::Rails)
61
- schedule.instance_eval do
62
- @old_around_trigger = method :around_trigger
63
- def around_trigger(job)
64
- ::Rails.application.reloader.wrap do
65
- @old_around_trigger.call(job){ yield }
66
- end
65
+ around_action do |job_proc|
66
+ ::Rails.application.reloader.wrap do
67
+ job_proc.call
67
68
  end
68
69
  end
69
70
  end
@@ -1,3 +1,3 @@
1
1
  class RubyClock
2
- VERSION = "2.0.0.beta2"
2
+ VERSION = "2.0.0.beta3"
3
3
  end
data/lib/ruby-clock.rb CHANGED
@@ -6,7 +6,19 @@ class RubyClock
6
6
 
7
7
  include Singleton
8
8
 
9
- attr_accessor :on_error
9
+ attr_accessor :on_error, :around_actions
10
+
11
+ def initialize
12
+ @around_actions = []
13
+
14
+ def schedule.around_trigger(job_info, &job_proc)
15
+ RubyClock.instance.call_with_around_action_stack(
16
+ RubyClock.instance.around_actions.reverse,
17
+ job_proc,
18
+ job_info
19
+ )
20
+ end
21
+ end
10
22
 
11
23
  def wait_seconds
12
24
  ENV['RUBY_CLOCK_SHUTDOWN_WAIT_SECONDS']&.to_i || 29
@@ -116,4 +128,17 @@ class RubyClock
116
128
  end
117
129
  end
118
130
 
131
+ def call_with_around_action_stack(wrappers, job_proc, job_info)
132
+ case wrappers.count
133
+ when 0
134
+ job_proc.call(job_info)
135
+ else
136
+ call_with_around_action_stack(
137
+ wrappers[1..],
138
+ Proc.new{ wrappers.first.call(job_proc, job_info) },
139
+ job_info
140
+ )
141
+ end
142
+ end
143
+
119
144
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-clock
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta2
4
+ version: 2.0.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Bachir
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-15 00:00:00.000000000 Z
11
+ date: 2022-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rufus-scheduler