ruby-clock 2.0.0.beta1 → 2.0.0.beta2
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/CHANGELOG.md +10 -1
- data/README.md +27 -20
- data/example-app/Clockfile +7 -3
- data/example-rails-app/Clockfile +9 -5
- data/exe/clock +31 -5
- data/lib/ruby-clock/version.rb +2 -2
- data/lib/ruby-clock.rb +12 -2
- data/ruby-clock.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fdfa3656f0ffbdf60b162a594809e29e9f0579cf3f5f52e98ffd857a811c348
|
4
|
+
data.tar.gz: f63dd579f2cd258f89f17666338ec9d433a63e2b93d0a400975ee6c1e61886fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 938ec658ba3837be8a90c49fdd8d2d6a050b1b6a19486bc2b10479e81370ed3fe5c0e4501293b02a2c8efcfe82d67974e887c2069270986f3398b89762c04707
|
7
|
+
data.tar.gz: c3376b79456a66c2b3c1eb5492b9a0429e69ece7b5207a73d2792c8830c33355c14dc622c2a37e8b6b8e2b9b27cdaaa4d0c83449e6e9c8aca3ae2538e2a90af0
|
data/CHANGELOG.md
CHANGED
@@ -1,16 +1,25 @@
|
|
1
|
-
## 2.0.0
|
1
|
+
## 2.0.0 beta
|
2
2
|
|
3
3
|
* The way the [rails app reloader](https://guides.rubyonrails.org/threading_and_code_execution.html)
|
4
4
|
is implemented is now compatible with both rails 6 and 7
|
5
5
|
* The setup for rails is now less complicated
|
6
|
+
* RUBY_CLOCK_SHUTDOWN_WAIT_SECONDS value is logged when starting
|
7
|
+
* Code reorganization so there are no unnecessary methods in top-level Kernel namespace
|
8
|
+
* DSL methods are now at the top-level namespace (`schedule.every` → `every`, `schedule.cron` → `cron`)
|
9
|
+
* error handler definition is now at the top-level namespace (`def schedule.on_error` → `on_error do`)
|
6
10
|
|
7
11
|
### Migrating from ruby-clock version 1 to version 2
|
8
12
|
|
9
13
|
* There is no longer a need to have a binstub in rails. You can delete bin/clock from your app.
|
10
14
|
* The invocations (in Procfile, or wherever else you start ruby-clock) should change from
|
15
|
+
|
11
16
|
bundle exec rails runner bin/clock
|
12
17
|
to
|
18
|
+
|
13
19
|
bundle exec clock
|
20
|
+
* Your existing Clockfile will still work, but you now have the option to use
|
21
|
+
`every`, `cron`, and `on_error` at the top-level, without referencing `schedule`.
|
22
|
+
See the readme for examples.
|
14
23
|
|
15
24
|
## 1.0.0
|
16
25
|
|
data/README.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
THESE ARE THE DOCS FOR VERSION 2.0.0.beta2
|
2
|
+
|
3
|
+
See version 1 docs here: https://github.com/jjb/ruby-clock/tree/v1.0.0
|
4
|
+
|
1
5
|
# ruby-clock
|
2
6
|
|
3
7
|
ruby-clock is a [job scheduler](https://en.wikipedia.org/wiki/Job_scheduler),
|
@@ -24,6 +28,8 @@ You can change this number with `RUBY_CLOCK_SHUTDOWN_WAIT_SECONDS` in the enviro
|
|
24
28
|
|
25
29
|
## Installation
|
26
30
|
|
31
|
+
ruby >= 2.7 is required.
|
32
|
+
|
27
33
|
Add these lines to your application's Gemfile:
|
28
34
|
|
29
35
|
```ruby
|
@@ -41,17 +47,15 @@ Or install it yourself as:
|
|
41
47
|
## Usage
|
42
48
|
|
43
49
|
Create a file named Clockfile. This will hold your job definitions.
|
44
|
-
|
45
|
-
are the same as those of [rufus-scheduler](https://github.com/jmettraux/rufus-scheduler/).
|
46
|
-
Read the rufus-scheduler documentation to see what you can do.
|
50
|
+
Define jobs like this:
|
47
51
|
|
48
52
|
```ruby
|
49
|
-
|
53
|
+
every('5 minutes') do
|
50
54
|
UserDataReports.generate
|
51
55
|
end
|
52
56
|
|
53
57
|
# do something every day, five minutes after midnight
|
54
|
-
|
58
|
+
cron '5 0 * * *' do
|
55
59
|
DailyActivitySummary.generate_and_send
|
56
60
|
end
|
57
61
|
```
|
@@ -99,7 +103,7 @@ Require your app's code at the top of Clockfile:
|
|
99
103
|
|
100
104
|
```ruby
|
101
105
|
require_relative './lib/app.rb'
|
102
|
-
|
106
|
+
every('5 minutes') do
|
103
107
|
...
|
104
108
|
```
|
105
109
|
|
@@ -141,7 +145,7 @@ You can catch and report errors raised in your jobs by defining an error catcher
|
|
141
145
|
the top of your Clockfile like this:
|
142
146
|
|
143
147
|
```ruby
|
144
|
-
|
148
|
+
on_error do |job, error|
|
145
149
|
ErrorReporter.track_exception(error)
|
146
150
|
end
|
147
151
|
```
|
@@ -157,7 +161,7 @@ to learn how to do this. Where the documentation references `s`, you should use
|
|
157
161
|
You can run shell commands in your jobs.
|
158
162
|
|
159
163
|
```ruby
|
160
|
-
|
164
|
+
every '1 day' do
|
161
165
|
shell('sh scripts/process_stuff.sh')
|
162
166
|
end
|
163
167
|
```
|
@@ -172,7 +176,7 @@ If you want to use other terrapin features, you can skip the `shell` command
|
|
172
176
|
and use terrapin directly:
|
173
177
|
|
174
178
|
```ruby
|
175
|
-
|
179
|
+
every '1 day' do
|
176
180
|
line = Terrapin::CommandLine.new('optimize_png', ":file")
|
177
181
|
Organization.with_new_logos.find_each do |o|
|
178
182
|
line.run(file: o.logo_file_path)
|
@@ -203,7 +207,7 @@ You can run tasks from within the persistent runtime of ruby-clock, without
|
|
203
207
|
needing to shell out and start another process.
|
204
208
|
|
205
209
|
```ruby
|
206
|
-
|
210
|
+
every '1 day' do
|
207
211
|
rake('reports:daily')
|
208
212
|
end
|
209
213
|
```
|
@@ -222,12 +226,12 @@ fallback is the line number of the job in Clockfile.
|
|
222
226
|
Some examples of jobs and their identifiers:
|
223
227
|
|
224
228
|
```ruby
|
225
|
-
|
229
|
+
every '1 second', name: 'my job' do
|
226
230
|
Foo.bar
|
227
231
|
end
|
228
232
|
# => my job
|
229
233
|
|
230
|
-
|
234
|
+
every '1 day' do
|
231
235
|
daily_things = Foo.setup_daily
|
232
236
|
daily_things.process
|
233
237
|
# TODO: figure out best time of day
|
@@ -235,7 +239,7 @@ end
|
|
235
239
|
# => daily_things.process
|
236
240
|
|
237
241
|
# n.b. ruby-clock isn't yet smart enough to remove trailing comments
|
238
|
-
|
242
|
+
every '1 week' do
|
239
243
|
weekly_things = Foo.setup_weekly
|
240
244
|
weekly_things.process # does this work???!1~
|
241
245
|
end
|
@@ -253,7 +257,7 @@ def schedule.on_post_trigger(job, trigger_time)
|
|
253
257
|
StatsTracker.increment('Clock: Job Executions')
|
254
258
|
end
|
255
259
|
|
256
|
-
|
260
|
+
every '10 seconds', name: 'thread stats' do
|
257
261
|
thread_usage = Hash.new(0)
|
258
262
|
schedule.work_threads(:active).each do |t|
|
259
263
|
thread_usage[t[:rufus_scheduler_job].identifier] += 1
|
@@ -268,14 +272,17 @@ schedule.every '10 seconds', name: 'thread stats' do
|
|
268
272
|
end
|
269
273
|
```
|
270
274
|
|
271
|
-
###
|
275
|
+
### Other rufus-scheduler Options
|
272
276
|
|
273
|
-
All rufus-scheduler options are set to defaults.
|
274
|
-
available in your Clockfile is
|
275
|
-
|
277
|
+
All [rufus-scheduler](https://github.com/jmettraux/rufus-scheduler/) options are set to defaults.
|
278
|
+
There is a `schedule` variable available in your Clockfile, which is the singleton instance of `Rufus::Scheduler`.
|
279
|
+
ruby-clock methods such as `every` and `cron` are convenience methods which invoke `schedule.every`
|
280
|
+
and `schedule.cron`.
|
281
|
+
Anything you can do on this instance, you can do in your Clockfile.
|
282
|
+
See the rufus-scheduler documentation to see what you can do.
|
276
283
|
|
277
|
-
|
278
|
-
|
284
|
+
If you have ideas for rufus-scheduler features that can be brought in as
|
285
|
+
more abstract or default ruby-clock behavior, let me know!
|
279
286
|
|
280
287
|
## Syntax highlighting for Clockfile
|
281
288
|
|
data/example-app/Clockfile
CHANGED
@@ -1,11 +1,15 @@
|
|
1
|
-
|
1
|
+
on_error do |job, error|
|
2
2
|
raise error
|
3
3
|
end
|
4
4
|
|
5
|
-
|
5
|
+
every('2 seconds') do
|
6
6
|
puts "hello from a ruby-clock job"
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
every('2 seconds') do
|
10
10
|
shell 'say hello'
|
11
11
|
end
|
12
|
+
|
13
|
+
cron('*/10 * * * * *') do
|
14
|
+
puts "cron running on every 10th second #{Time.now}"
|
15
|
+
end
|
data/example-rails-app/Clockfile
CHANGED
@@ -1,19 +1,23 @@
|
|
1
|
-
|
1
|
+
on_error do |job, error|
|
2
2
|
puts "An error has occurred: #{error.class}: #{error.message}"
|
3
3
|
end
|
4
4
|
|
5
|
-
|
5
|
+
every('2 seconds') do
|
6
6
|
puts "hello from a ruby-clock job"
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
every('2 seconds') do
|
10
10
|
shell 'say hello'
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
every('2 seconds') do
|
14
14
|
puts Example.count
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
every('2 seconds') do
|
18
18
|
raise "An error."
|
19
19
|
end
|
20
|
+
|
21
|
+
cron('*/10 * * * * *') do
|
22
|
+
puts "cron running on every 10th second #{Time.now}"
|
23
|
+
end
|
data/exe/clock
CHANGED
@@ -23,11 +23,37 @@ class Rufus::Scheduler::Job
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
RubyClock.instance.listen_to_signals
|
27
|
+
RubyClock.instance.prepare_rake
|
28
|
+
RubyClock.instance.schedule.pause
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
## Add methods to top-level namespace
|
33
|
+
def schedule
|
34
|
+
RubyClock.instance.schedule
|
35
|
+
end
|
36
|
+
|
37
|
+
def on_error(&on_error_block)
|
38
|
+
RubyClock.instance.on_error = on_error_block
|
39
|
+
def schedule.on_error(job, error)
|
40
|
+
RubyClock.instance.on_error.call(job, error)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def cron(...)
|
45
|
+
RubyClock.instance.schedule.cron(...)
|
46
|
+
end
|
47
|
+
|
48
|
+
def every(...)
|
49
|
+
RubyClock.instance.schedule.every(...)
|
50
|
+
end
|
51
|
+
|
52
|
+
def shell(string)
|
53
|
+
RubyClock.instance.shell(string)
|
54
|
+
end
|
55
|
+
#####################################
|
27
56
|
|
28
|
-
listen_to_signals
|
29
|
-
prepare_rake
|
30
|
-
schedule.pause
|
31
57
|
|
32
58
|
load ARGV[0] || 'Clockfile'
|
33
59
|
|
@@ -42,4 +68,4 @@ if defined?(::Rails)
|
|
42
68
|
end
|
43
69
|
end
|
44
70
|
|
45
|
-
run_jobs
|
71
|
+
RubyClock.instance.run_jobs
|
data/lib/ruby-clock/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "2.0.0.
|
1
|
+
class RubyClock
|
2
|
+
VERSION = "2.0.0.beta2"
|
3
3
|
end
|
data/lib/ruby-clock.rb
CHANGED
@@ -1,9 +1,18 @@
|
|
1
1
|
require "ruby-clock/version"
|
2
2
|
require 'rufus-scheduler'
|
3
|
+
require 'singleton'
|
4
|
+
|
5
|
+
class RubyClock
|
6
|
+
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
attr_accessor :on_error
|
10
|
+
|
11
|
+
def wait_seconds
|
12
|
+
ENV['RUBY_CLOCK_SHUTDOWN_WAIT_SECONDS']&.to_i || 29
|
13
|
+
end
|
3
14
|
|
4
|
-
module RubyClock
|
5
15
|
def shutdown
|
6
|
-
wait_seconds = ENV['RUBY_CLOCK_SHUTDOWN_WAIT_SECONDS']&.to_i || 29
|
7
16
|
puts "Shutting down ruby-clock. Waiting #{wait_seconds} seconds for jobs to finish..."
|
8
17
|
schedule.shutdown(wait: wait_seconds)
|
9
18
|
puts "...done 🐈️ 👋"
|
@@ -21,6 +30,7 @@ module RubyClock
|
|
21
30
|
end
|
22
31
|
end
|
23
32
|
end
|
33
|
+
puts "RUBY_CLOCK_SHUTDOWN_WAIT_SECONDS is set to #{wait_seconds}"
|
24
34
|
end
|
25
35
|
|
26
36
|
def schedule
|
data/ruby-clock.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
11
11
|
spec.homepage = "https://github.com/jjb/ruby-clock"
|
12
12
|
spec.license = "MIT"
|
13
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
14
14
|
|
15
15
|
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
16
16
|
|
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.
|
4
|
+
version: 2.0.0.beta2
|
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-
|
11
|
+
date: 2022-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rufus-scheduler
|
@@ -159,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
159
159
|
requirements:
|
160
160
|
- - ">="
|
161
161
|
- !ruby/object:Gem::Version
|
162
|
-
version: 2.
|
162
|
+
version: 2.7.0
|
163
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
164
|
requirements:
|
165
165
|
- - ">"
|