ruby-clock 0.8.0.rc1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +6 -4
- data/README.md +50 -8
- data/example-app/.gitattributes +1 -0
- data/example-app/Clockfile +11 -0
- data/example-app/Gemfile +7 -0
- data/{Gemfile.lock → example-app/Gemfile.lock} +4 -12
- data/example-app/README.md +9 -0
- data/exe/clock +1 -1
- data/lib/ruby-clock/version.rb +1 -1
- data/lib/ruby-clock.rb +35 -2
- data/release.md +1 -0
- data/ruby-clock.gemspec +0 -2
- metadata +14 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb7709e5cb45330de5b30adb906cc15e847207894a2ad71b3afd706ea0235f09
|
4
|
+
data.tar.gz: 9ab66e406ada9646d83f28806c07018641953b7b56f8824b49e14b3bd2ad2b7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d14858bb6c936e07e66527c9f670d68e236d56ccce407da9c5472334748a3b3f07012f82ff827fb314557b318a555a0e50ff9914b36330fe9cbd7c271da76532
|
7
|
+
data.tar.gz: '033369b93174cdba782d21fa150f63f521bf058d9ef6a654fbb54fd53e2b529f753350b5e086aa2b7e5df2cd0647cf9f932aceb6aaeabba892727dfb978ed1a8'
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
## 0.
|
1
|
+
## 1.0.0
|
2
2
|
|
3
|
-
*
|
4
|
-
*
|
3
|
+
* make terrapin and posix-spawn gems optional
|
4
|
+
* fix detection of Rails constant, for non-rails apps
|
5
|
+
* automatically wrap jobs with rails reloader
|
5
6
|
* ability to run rake tasks
|
6
7
|
* ability to run shell commands
|
7
|
-
*
|
8
|
+
* nicer shutdown logging, indicating when shutdown process begins and ends
|
9
|
+
* fix approach for error fallbacks when when calculating job identifier (probably never encountered)
|
8
10
|
|
9
11
|
## 0.7.0
|
10
12
|
|
data/README.md
CHANGED
@@ -12,8 +12,8 @@ ruby-clock does.
|
|
12
12
|
|
13
13
|
Jobs are all run in their own parallel threads within the same process.
|
14
14
|
|
15
|
-
The clock process will respond to signals INT (
|
16
|
-
TERM (signal sent by environments such as Heroku and other PaaS's when shutting down).
|
15
|
+
The clock process will respond to signals `INT` (<kbd>^c</kbd> at the command line) and
|
16
|
+
`TERM` (signal sent by environments such as Heroku and other PaaS's when shutting down).
|
17
17
|
In both cases, the clock will stop running jobs and give existing jobs 29 seconds
|
18
18
|
to stop before killing them.
|
19
19
|
You can change this number with `RUBY_CLOCK_SHUTDOWN_WAIT_SECONDS` in the environment.
|
@@ -75,7 +75,22 @@ To get smarter database connection management (such as in the case of a database
|
|
75
75
|
and maybe other benefits) and code reloading in dev (app code, not the code in Clockfile itself),
|
76
76
|
jobs are automatically wrapped in the
|
77
77
|
[rails app reloader](https://guides.rubyonrails.org/threading_and_code_execution.html).
|
78
|
+
This [may incur a performance impact for certain jobs](https://github.com/rails/rails/issues/43504),
|
79
|
+
I'm still exploring this.
|
78
80
|
|
81
|
+
#### ActiveRecord Query Cache
|
82
|
+
|
83
|
+
You may wish to
|
84
|
+
[turn off the ActiveRecord Query Cache](https://code.jjb.cc/turning-off-activerecord-query-cache-to-improve-memory-consumption-in-background-jobs)
|
85
|
+
for your jobs. You can do so with the around trigger:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
def schedule.around_trigger(job)
|
89
|
+
ActiveRecord::Base.uncached do
|
90
|
+
yield
|
91
|
+
end
|
92
|
+
end
|
93
|
+
```
|
79
94
|
|
80
95
|
### Non-Rails
|
81
96
|
|
@@ -108,6 +123,14 @@ thing_reporter: bundle exec rails runner bin/clock clocks/thing_reporter.rb
|
|
108
123
|
|
109
124
|
Because of this feature, do I regret using "Clockfile" instead of, say, "clock.rb"? Maybe.
|
110
125
|
|
126
|
+
#### Observing logs
|
127
|
+
|
128
|
+
Because STDOUT does not flush until a certain amount of data has gone into it,
|
129
|
+
you might not immediately see the ruby-clock startup message or job output if
|
130
|
+
viewing logs in a deployed environment such as Heroku where the logs are redirected
|
131
|
+
to another process or file. To change this behavior and have logs flush immediately,
|
132
|
+
add `$stdout.sync = true` to the top of your Clockfile.
|
133
|
+
|
111
134
|
|
112
135
|
## More Config and Capabilities
|
113
136
|
|
@@ -130,9 +153,7 @@ to learn how to do this. Where the documentation references `s`, you should use
|
|
130
153
|
|
131
154
|
### Shell commands
|
132
155
|
|
133
|
-
You can run shell commands in your jobs.
|
134
|
-
[posix-spawn](https://github.com/rtomayko/posix-spawn), which means
|
135
|
-
the ruby process is not forked.
|
156
|
+
You can run shell commands in your jobs.
|
136
157
|
|
137
158
|
```ruby
|
138
159
|
schedule.every '1 day' do
|
@@ -140,9 +161,14 @@ schedule.every '1 day' do
|
|
140
161
|
end
|
141
162
|
```
|
142
163
|
|
143
|
-
|
144
|
-
[
|
145
|
-
|
164
|
+
By default they will be run with
|
165
|
+
[ruby backticks](https://livebook.manning.com/concept/ruby/backtick).
|
166
|
+
For better performance, install the [terrapin](https://github.com/thoughtbot/terrapin)
|
167
|
+
and [posix-spawn](https://github.com/rtomayko/posix-spawn) gems.
|
168
|
+
|
169
|
+
`shell` is a convenience method which just passes the string on.
|
170
|
+
If you want to use other terrapin features, you can skip the `shell` command
|
171
|
+
and use terrapin directly:
|
146
172
|
|
147
173
|
```ruby
|
148
174
|
schedule.every '1 day' do
|
@@ -154,6 +180,22 @@ schedule.every '1 day' do
|
|
154
180
|
end
|
155
181
|
```
|
156
182
|
|
183
|
+
#### shutdown behavior
|
184
|
+
|
185
|
+
Because of [this](https://stackoverflow.com/questions/69653842/),
|
186
|
+
if a shell job is running during shutdown, shutdown behavior seems to be changed
|
187
|
+
for _all_ running jobs - they no longer are allowed to finish within the timeout period.
|
188
|
+
Everything exits immediately.
|
189
|
+
|
190
|
+
Until this is figured out, if you are concerned about jobs exiting inelegantly,
|
191
|
+
you may want to run your shell jobs in their own separate clock process.
|
192
|
+
|
193
|
+
```
|
194
|
+
bundle exec rails runner bin/clock clocks/main_jobs.rb
|
195
|
+
bundle exec rails runner bin/clock clocks/shell_jobs.rb
|
196
|
+
```
|
197
|
+
|
198
|
+
|
157
199
|
### Rake tasks
|
158
200
|
|
159
201
|
You can run tasks from within the persistent runtime of ruby-clock, without
|
@@ -0,0 +1 @@
|
|
1
|
+
Clockfile linguist-language=Ruby
|
data/example-app/Gemfile
ADDED
@@ -1,16 +1,13 @@
|
|
1
1
|
PATH
|
2
|
-
remote:
|
2
|
+
remote: ..
|
3
3
|
specs:
|
4
|
-
ruby-clock (0.8.0.
|
4
|
+
ruby-clock (0.8.0.rc3)
|
5
5
|
method_source
|
6
|
-
posix-spawn (~> 0.3.15)
|
7
6
|
rufus-scheduler (~> 3.8)
|
8
|
-
terrapin (~> 0.6)
|
9
7
|
|
10
8
|
GEM
|
11
9
|
remote: https://rubygems.org/
|
12
10
|
specs:
|
13
|
-
climate_control (0.2.0)
|
14
11
|
concurrent-ruby (1.1.9)
|
15
12
|
et-orbi (1.2.5)
|
16
13
|
tzinfo
|
@@ -18,22 +15,17 @@ GEM
|
|
18
15
|
et-orbi (~> 1.1, >= 1.1.8)
|
19
16
|
raabro (~> 1.4)
|
20
17
|
method_source (1.0.0)
|
21
|
-
posix-spawn (0.3.15)
|
22
18
|
raabro (1.4.0)
|
23
|
-
rake (12.3.3)
|
24
19
|
rufus-scheduler (3.8.0)
|
25
20
|
fugit (~> 1.1, >= 1.1.6)
|
26
|
-
terrapin (0.6.0)
|
27
|
-
climate_control (>= 0.0.3, < 1.0)
|
28
21
|
tzinfo (2.0.4)
|
29
22
|
concurrent-ruby (~> 1.0)
|
30
23
|
|
31
24
|
PLATFORMS
|
32
|
-
|
25
|
+
arm64-darwin-20
|
33
26
|
|
34
27
|
DEPENDENCIES
|
35
|
-
rake (~> 12.0)
|
36
28
|
ruby-clock!
|
37
29
|
|
38
30
|
BUNDLED WITH
|
39
|
-
2.2.
|
31
|
+
2.2.28
|
data/exe/clock
CHANGED
data/lib/ruby-clock/version.rb
CHANGED
data/lib/ruby-clock.rb
CHANGED
@@ -42,7 +42,7 @@ module RubyClock
|
|
42
42
|
puts <<~MESSAGE
|
43
43
|
Because this is not a rails application, we do not know how to load your
|
44
44
|
rake tasks. You can do this yourself at the top of your Clockfile if you want
|
45
|
-
to run rake tasks from ruby-
|
45
|
+
to run rake tasks from ruby-clock.
|
46
46
|
MESSAGE
|
47
47
|
end
|
48
48
|
end
|
@@ -69,8 +69,41 @@ module RubyClock
|
|
69
69
|
@rake_mutex.synchronize { rake_async(task) }
|
70
70
|
end
|
71
71
|
|
72
|
+
def shell_runner
|
73
|
+
@shell_runner ||= begin
|
74
|
+
require 'terrapin'
|
75
|
+
require 'posix-spawn'
|
76
|
+
|
77
|
+
unless Terrapin::CommandLine.runner.class == Terrapin::CommandLine::PosixRunner
|
78
|
+
puts <<~MESSAGE
|
79
|
+
|
80
|
+
🤷 terrapin and posix-spawn are installed, but for some reason terrapin is
|
81
|
+
not using posix-spawn as its runner.
|
82
|
+
|
83
|
+
MESSAGE
|
84
|
+
end
|
85
|
+
|
86
|
+
puts '🐆 Using terrapin for shell commands.'
|
87
|
+
:terrapin
|
88
|
+
rescue LoadError
|
89
|
+
puts <<~MESSAGE
|
90
|
+
|
91
|
+
🦥 Using ruby backticks for shell commands.
|
92
|
+
For better performance, install the terrapin and posix-spawn gems.
|
93
|
+
See README.md for more info.
|
94
|
+
|
95
|
+
MESSAGE
|
96
|
+
:backticks
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
72
100
|
def shell(command)
|
73
|
-
|
101
|
+
case shell_runner
|
102
|
+
when :terrapin
|
103
|
+
Terrapin::CommandLine.new(command).run
|
104
|
+
when :backticks
|
105
|
+
`#{command}`
|
106
|
+
end
|
74
107
|
end
|
75
108
|
|
76
109
|
end
|
data/release.md
CHANGED
data/ruby-clock.gemspec
CHANGED
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: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Bachir
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rufus-scheduler
|
@@ -38,35 +38,7 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
|
42
|
-
name: terrapin
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0.6'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0.6'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: posix-spawn
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 0.3.15
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 0.3.15
|
69
|
-
description:
|
41
|
+
description:
|
70
42
|
email:
|
71
43
|
- j@jjb.cc
|
72
44
|
executables:
|
@@ -77,12 +49,16 @@ files:
|
|
77
49
|
- ".gitignore"
|
78
50
|
- CHANGELOG.md
|
79
51
|
- Gemfile
|
80
|
-
- Gemfile.lock
|
81
52
|
- LICENSE.txt
|
82
53
|
- README.md
|
83
54
|
- Rakefile
|
84
55
|
- bin/console
|
85
56
|
- bin/setup
|
57
|
+
- example-app/.gitattributes
|
58
|
+
- example-app/Clockfile
|
59
|
+
- example-app/Gemfile
|
60
|
+
- example-app/Gemfile.lock
|
61
|
+
- example-app/README.md
|
86
62
|
- exe/clock
|
87
63
|
- lib/ruby-clock.rb
|
88
64
|
- lib/ruby-clock/version.rb
|
@@ -94,7 +70,7 @@ licenses:
|
|
94
70
|
metadata:
|
95
71
|
homepage_uri: https://github.com/jjb/ruby-clock
|
96
72
|
source_code_uri: https://github.com/jjb/ruby-clock
|
97
|
-
post_install_message:
|
73
|
+
post_install_message:
|
98
74
|
rdoc_options: []
|
99
75
|
require_paths:
|
100
76
|
- lib
|
@@ -105,12 +81,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
81
|
version: 2.3.0
|
106
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
83
|
requirements:
|
108
|
-
- - "
|
84
|
+
- - ">="
|
109
85
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
86
|
+
version: '0'
|
111
87
|
requirements: []
|
112
|
-
rubygems_version: 3.2.
|
113
|
-
signing_key:
|
88
|
+
rubygems_version: 3.2.22
|
89
|
+
signing_key:
|
114
90
|
specification_version: 4
|
115
91
|
summary: A "clock" process for invoking ruby code within a persistent runtime
|
116
92
|
test_files: []
|