ruby-clock 2.0.0.beta6 → 2.0.0.beta8

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: 748f887bbd3b6076b86585e8734f2fc131ec3312bd10c330e5adc867643d7776
4
- data.tar.gz: 8c449e3389930814e009ad6850e1a5e4a049ffe0e50364f834dc0b1e1cef1def
3
+ metadata.gz: 315bcc30c6fc32c1676e452750d76e839b0123f19fe7512bbe6662ae72ee0ecc
4
+ data.tar.gz: a5831b721e9d99af3082cb31dd472f4e282d5665616f40694ba41def7250b907
5
5
  SHA512:
6
- metadata.gz: 85af8021686f2148b0f295fdd4b0c0e3eba7457a3a060f34d1f9fed67ff17ab6ba2f62983912ee481dea45db14a547ffe6b496a6fea59986e271e66f768a0212
7
- data.tar.gz: da361427d50908de9c9a4a949a284831536fbf2e0f1980a9906f23d19e80150d3f1f4085031df06850a63529a23eddb7d48956de7352ff2679d6c026eced8e2e
6
+ metadata.gz: '0983e40393e4d273feddbcb53d67c0a8b2ccbb194439a16df9ddb1edaeedcf89f36338bffc80d8ffb44809500b3553cbc601c55275fcd4dba86d18b67ad57bf5'
7
+ data.tar.gz: 563039f0ea34927b4d6e1abd64db0f2ae086c44f37d03852d8ca510223e1ce0f57ebe275ce7059d704de3e29a1e7f33d1412b92ad4b7a5a7e4e6d5ec661e9605
data/CHANGELOG.md CHANGED
@@ -6,10 +6,17 @@
6
6
  * RUBY_CLOCK_SHUTDOWN_WAIT_SECONDS value is logged when starting
7
7
  * DSL methods are now at the top-level namespace (`schedule.every` → `every`, `schedule.cron` → `cron`)
8
8
  * Error handler definition is now at the top-level namespace (`def schedule.on_error` → `on_error do`)
9
- * Around callbacks now have a top-level namespace method. `def schedule.around_trigger` → `around_action` - see readme
10
- * Multiple around callbacks can be consecutively assigned - no need to put all behavior into one action
11
- * Errors encountered when loading Clockfile (such as incorrect cron syntaxt)
9
+ * Around callbacks now have a top-level namespace method. `def schedule.around_trigger` → `around_action do`
10
+ * Multiple around callbacks can be consecutively assigned - no need to put all behavior into one method
11
+ * Errors encountered when loading Clockfile (such as incorrect cron syntax)
12
12
  will be reported to the error handler
13
+ * The automatic identifier generator will now ignore `}` and `end` lines
14
+ * posix-spawn is no longer used. In ruby 3, native `Process.spawn` is more performant. See
15
+ [posix-spawn#90](https://github.com/rtomayko/posix-spawn/issues/90)
16
+ and
17
+ [terrapin#19](https://github.com/thoughtbot/terrapin/pull/19)
18
+ for more info.
19
+ * `--environment-and-syntax-check` capability
13
20
 
14
21
  ### Anti-Features
15
22
  * ruby 3.0 is now the minimum version
@@ -26,11 +33,9 @@
26
33
  * The top of every Clockfile must begin with `using RubyClock::DSL`
27
34
  * If you have an existing `def schedule.around_trigger`, you will need to change it to use the new
28
35
  `around_action` method.
29
- * Your existing Clockfile will still work, but you now have the option to use
36
+ * Your existing Clockfile with `schedule.foo` invocations will still work, but you now have the option to use
30
37
  `every`, `cron`, and `on_error` at the top-level, without referencing `schedule`.
31
- See the readme for examples.
32
38
  * You now have the option of catching and reporting errors encountered when parsing the Clockfile.
33
- See the readme.
34
39
  * There is no longer a need to have a binstub in rails. You can delete bin/clock from your app.
35
40
  * The invocations (in Procfile, or wherever else you start ruby-clock) should change from
36
41
 
data/README.md CHANGED
@@ -28,7 +28,7 @@ You can change this number with `RUBY_CLOCK_SHUTDOWN_WAIT_SECONDS` in the enviro
28
28
 
29
29
  ## Installation
30
30
 
31
- ruby >= 2.7 is required.
31
+ ruby >= 3.0 is required.
32
32
 
33
33
  Add these lines to your application's Gemfile:
34
34
 
@@ -139,6 +139,17 @@ to another process or file. To change this behavior and have logs flush immediat
139
139
  add `$stdout.sync = true` to the top of your Clockfile.
140
140
 
141
141
 
142
+ #### Testing
143
+
144
+ You can use the `--environment-and-syntax-check` flag to load the app environment and check
145
+ Clockfile syntax without actually running jobs. This can be used to check if cron syntax
146
+ is valid during dev, or in automate tests.
147
+
148
+ ```ruby
149
+ # system returns true/false depending on 0/1 exit status of process
150
+ assert(system("bundle exec --environment-and-syntax-check clock/my_clockfile.rb"))
151
+ ```
152
+
142
153
  ## More Config and Capabilities
143
154
 
144
155
  ### Error Handling
@@ -151,7 +162,7 @@ error reports about problems while loading the Clockfile:
151
162
  on_error do |job, error|
152
163
  case job
153
164
  when String # this means there was a problem parsing the Clockfile while starting
154
- ErrorReporter.track_exception(error, tag: 'clock', severity: 'high')
165
+ ErrorReporter.track_exception(StandardError.new(error), tag: 'clock', severity: 'high')
155
166
  else
156
167
  ErrorReporter.track_exception(error, tag: 'clock', custom_attribute: {job_name: job.identifier})
157
168
  end
@@ -239,7 +250,7 @@ end
239
250
  By default they will be run with
240
251
  [ruby backticks](https://livebook.manning.com/concept/ruby/backtick).
241
252
  For better performance, install the [terrapin](https://github.com/thoughtbot/terrapin)
242
- and [posix-spawn](https://github.com/rtomayko/posix-spawn) gems.
253
+ gem.
243
254
 
244
255
  `shell` is a convenience method which just passes the string on.
245
256
  If you want to use other terrapin features, you can skip the `shell` command
@@ -283,7 +294,7 @@ end
283
294
  ```
284
295
 
285
296
  There are also `rake_execute` and `rake_async`.
286
- See [the code](https://github.com/jjb/ruby-clock/blob/main/lib/rake.rb)
297
+ See [the code](https://github.com/jjb/ruby-clock/blob/main/lib/ruby-clock/rake.rb)
287
298
  and [this article](https://code.jjb.cc/running-rake-tasks-from-within-ruby-on-rails-code) for more info.
288
299
 
289
300
  ### Job Identifier
@@ -14,7 +14,7 @@ end
14
14
  # end
15
15
 
16
16
  around_action do |job_proc, job_info|
17
- puts "before1 #{job_info.class}"
17
+ puts "before1 #{job_info.class} #{job_info.identifier}"
18
18
  job_proc.call
19
19
  puts "after1"
20
20
  end
@@ -60,3 +60,19 @@ end
60
60
  # def schedule.around_trigger(job_info, &job_proc)
61
61
  # puts "ruby-clock 1-style around trigger!"
62
62
  # end
63
+
64
+ every('2 seconds', blocking: true) do
65
+ begin
66
+
67
+ 1.times {
68
+ begin
69
+ puts "hello from a stress test for the autonamer"
70
+ end
71
+
72
+ }
73
+ # this is a comment!
74
+
75
+ end
76
+ # another comment
77
+
78
+ end
data/example-app/Gemfile CHANGED
@@ -6,4 +6,3 @@ ruby '>= 3.0'
6
6
 
7
7
  gem 'ruby-clock', path: '../'
8
8
  # gem 'terrapin'
9
- # gem 'posix-spawn'
data/exe/clock CHANGED
@@ -9,8 +9,21 @@ RubyClock.instance.prepare_rake
9
9
  RubyClock.instance.schedule.pause
10
10
  RubyClock.instance.add_rails_executor_to_around_actions
11
11
 
12
+ clockfile = 'Clockfile'
13
+ check_syntax = false
14
+ case ARGV[0]
15
+ when '--environment-and-syntax-check'
16
+ check_syntax = true
17
+ case ARGV[1]
18
+ when String
19
+ clockfile = ARGV[1]
20
+ end
21
+ when String
22
+ clockfile = ARGV[0]
23
+ end
24
+
12
25
  begin
13
- load ARGV[0] || 'Clockfile'
26
+ load clockfile
14
27
  rescue => clockfile_error
15
28
  if RubyClock.instance.on_error
16
29
  RubyClock.instance.on_error.call("An error has occured while parsing the clockfile", clockfile_error)
@@ -21,4 +34,9 @@ end
21
34
 
22
35
  RubyClock.instance.ensure_around_trigger_has_not_been_redefined
23
36
  RubyClock.instance.freeze_around_actions
24
- RubyClock.instance.run_jobs
37
+
38
+ if check_syntax
39
+ puts "✨ Environment & Syntax OK ✨"
40
+ else
41
+ RubyClock.instance.run_jobs
42
+ end
@@ -2,13 +2,11 @@ module RubyClock::Shell
2
2
  def shell_runner
3
3
  @shell_runner ||= begin
4
4
  require 'terrapin'
5
- require 'posix-spawn'
6
-
7
- unless Terrapin::CommandLine.runner.class == Terrapin::CommandLine::PosixRunner
5
+ unless Terrapin::CommandLine.runner.class == Terrapin::CommandLine::ProcessRunner
8
6
  puts <<~MESSAGE
9
7
 
10
- 🤷 terrapin and posix-spawn are installed, but for some reason terrapin is
11
- not using posix-spawn as its runner.
8
+ 🤷 terrapin is installed, but for some reason terrapin is
9
+ using backticks as its runner.
12
10
 
13
11
  MESSAGE
14
12
  end
@@ -19,7 +17,7 @@ module RubyClock::Shell
19
17
  puts <<~MESSAGE
20
18
 
21
19
  🦥 Using ruby backticks for shell commands.
22
- For better performance, install the terrapin and posix-spawn gems.
20
+ For better performance, install the terrapin gem.
23
21
  See README.md for more info.
24
22
 
25
23
  MESSAGE
@@ -1,3 +1,3 @@
1
1
  class RubyClock
2
- VERSION = "2.0.0.beta6"
2
+ VERSION = "2.0.0.beta8"
3
3
  end
@@ -1,8 +1,15 @@
1
1
  require 'method_source'
2
2
  class Rufus::Scheduler::Job
3
+ UNDESIRED_ELEMENTS = ['', '}', 'end']
3
4
  def identifier
4
5
  @identifier ||= begin
5
- name || handler.source.split("\n").reject(&:empty?).grep_v(/#.*/)[-2].strip
6
+ return name if name
7
+
8
+ lines = handler.source.split("\n")
9
+ whitespace_removed = lines.map(&:strip)
10
+ undesired_removed = whitespace_removed - UNDESIRED_ELEMENTS
11
+ comment_only_lines_removed = undesired_removed.grep_v(/#.*/)
12
+ comment_only_lines_removed[-1] # final line
6
13
  rescue
7
14
  begin
8
15
  source_location.join('-')
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.beta6
4
+ version: 2.0.0.beta8
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-11-19 00:00:00.000000000 Z
11
+ date: 2023-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rufus-scheduler
@@ -276,7 +276,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
276
276
  - !ruby/object:Gem::Version
277
277
  version: 1.3.1
278
278
  requirements: []
279
- rubygems_version: 3.1.6
279
+ rubygems_version: 3.3.7
280
280
  signing_key:
281
281
  specification_version: 4
282
282
  summary: A job scheduler which runs jobs each in their own thread in a persistent