good_job 3.17.3 → 3.18.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
2
  SHA256:
3
- metadata.gz: 46ab9513d6943173f1c0c81f0755ac6870581595e2962ca0e438b32cdb9eec6e
4
- data.tar.gz: 0aeebddc6f1ad80fc1d0cba1c4d923b17c6d9bae2fcafdd3282fc9d6cf4ec57f
3
+ metadata.gz: cb40c03312f09c2cb91e77bce2ab3aacf87c62a18125d62b50bdc92b312d34f5
4
+ data.tar.gz: c1c73c9264b8bd6454aad7685d326d082c00d5c3f14667ab89e1f77cce9059ea
5
5
  SHA512:
6
- metadata.gz: 2c5491f403270ee5029dd1032d42421a721c996c35491198ee46901073dbc40fa3974e2d91d757905a474b524a3a3d8c8b27bae1d1ad661f0559d553df97dd7c
7
- data.tar.gz: 26d55dec3a1a9c5bcef140f612a391ee14688f686ffc9300ab7ed98309e692de21c6ef5c623794545fb9f754656d731dbc3146e8264ff060f902837b8ba379b8
6
+ metadata.gz: 9825b6d3c5a496c7fdee3aec3f0b5653a6c68d40b15487bb43d21b48817ae077052b3c3520b6ac0dd54354cc68b1157800270e95119240260ef68ab55046b293
7
+ data.tar.gz: a903a5cac7a8b753e457d7e98018ca575825dcb1be515702cd30bd92494f3fc22740e09e48c4b3a8312fae2824021e86d6f6d9e431d0b10f39c05ea97457baca
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## [v3.18.0](https://github.com/bensheldon/good_job/tree/v3.18.0) (2023-08-30)
4
+
5
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v3.17.4...v3.18.0)
6
+
7
+ **Implemented enhancements:**
8
+
9
+ - Support configuring cron schedule dynamically with a block [\#1051](https://github.com/bensheldon/good_job/pull/1051) ([DanielHeath](https://github.com/DanielHeath))
10
+
11
+ ## [v3.17.4](https://github.com/bensheldon/good_job/tree/v3.17.4) (2023-08-24)
12
+
13
+ [Full Changelog](https://github.com/bensheldon/good_job/compare/v3.17.3...v3.17.4)
14
+
15
+ **Fixed bugs:**
16
+
17
+ - Handle edge case of logger not responding to silence [\#1049](https://github.com/bensheldon/good_job/pull/1049) ([bensheldon](https://github.com/bensheldon))
18
+
19
+ **Closed issues:**
20
+
21
+ - An idea for better .silence handling [\#1046](https://github.com/bensheldon/good_job/issues/1046)
22
+
3
23
  ## [v3.17.3](https://github.com/bensheldon/good_job/tree/v3.17.3) (2023-08-19)
4
24
 
5
25
  [Full Changelog](https://github.com/bensheldon/good_job/compare/v3.17.2...v3.17.3)
data/README.md CHANGED
@@ -504,6 +504,10 @@ config.good_job.cron = {
504
504
  cron: "0 0,12 * * *",
505
505
  class: "AnotherJob",
506
506
  },
507
+ complex_schedule: {
508
+ class: "ComplexScheduleJob",
509
+ cron: -> (last_ran) { (last_ran.blank? ? Time.now : last_ran + 14.hours).at_beginning_of_minute }
510
+ }
507
511
  # etc.
508
512
  }
509
513
  ```
@@ -33,7 +33,7 @@ module GoodJob
33
33
  def self.with_logger_silenced(&block)
34
34
  # Assign to a local variable, just in case it's modified in another thread concurrently
35
35
  logger = self.logger
36
- if logger
36
+ if logger.respond_to? :silence
37
37
  logger.silence(&block)
38
38
  else
39
39
  yield
@@ -27,6 +27,7 @@ module GoodJob # :nodoc:
27
27
  def initialize(params = {})
28
28
  @params = params
29
29
 
30
+ return if cron_proc?
30
31
  raise ArgumentError, "Invalid cron format: '#{cron}'" unless fugit.instance_of?(Fugit::Cron)
31
32
  end
32
33
 
@@ -41,10 +42,6 @@ module GoodJob # :nodoc:
41
42
  params.fetch(:class)
42
43
  end
43
44
 
44
- def cron
45
- params.fetch(:cron)
46
- end
47
-
48
45
  def set
49
46
  params[:set]
50
47
  end
@@ -61,16 +58,21 @@ module GoodJob # :nodoc:
61
58
  params[:description]
62
59
  end
63
60
 
64
- def next_at
61
+ def next_at(previously_at: nil)
62
+ if cron_proc?
63
+ result = Rails.application.executor.wrap { cron.call(previously_at || last_at) }
64
+ return Fugit.parse(result).next_time.to_t if result.is_a?(String)
65
+
66
+ return result
67
+
68
+ end
65
69
  fugit.next_time.to_t
66
70
  end
67
71
 
68
72
  def schedule
69
- fugit.original
70
- end
73
+ return "Custom schedule" if cron_proc?
71
74
 
72
- def fugit
73
- @_fugit ||= Fugit.parse(cron)
75
+ fugit.original
74
76
  end
75
77
 
76
78
  def jobs
@@ -80,11 +82,7 @@ module GoodJob # :nodoc:
80
82
  def last_at
81
83
  return if last_job.blank?
82
84
 
83
- if GoodJob::Job.column_names.include?('cron_at')
84
- (last_job.cron_at || last_job.created_at).localtime
85
- else
86
- last_job.created_at
87
- end
85
+ (last_job.cron_at || last_job.created_at).localtime
88
86
  end
89
87
 
90
88
  def enabled?
@@ -116,11 +114,7 @@ module GoodJob # :nodoc:
116
114
  end
117
115
 
118
116
  def last_job
119
- if GoodJob::Job.column_names.include?('cron_at')
120
- jobs.order("cron_at DESC NULLS LAST").first
121
- else
122
- jobs.order(created_at: :asc).last
123
- end
117
+ jobs.order("cron_at DESC NULLS LAST").first
124
118
  end
125
119
 
126
120
  def display_properties
@@ -138,6 +132,18 @@ module GoodJob # :nodoc:
138
132
 
139
133
  private
140
134
 
135
+ def cron
136
+ params.fetch(:cron)
137
+ end
138
+
139
+ def cron_proc?
140
+ cron.respond_to?(:call)
141
+ end
142
+
143
+ def fugit
144
+ @_fugit ||= Fugit.parse(cron)
145
+ end
146
+
141
147
  def set_value
142
148
  value = set || {}
143
149
  value.respond_to?(:call) ? value.call : value
@@ -82,12 +82,13 @@ module GoodJob # :nodoc:
82
82
 
83
83
  # Enqueues a scheduled task
84
84
  # @param cron_entry [CronEntry] the CronEntry object to schedule
85
- def create_task(cron_entry)
86
- cron_at = cron_entry.next_at
85
+ # @param previously_at [Date, Time, ActiveSupport::TimeWithZone, nil] the last, +in-memory+, scheduled time the cron task was intended to run
86
+ def create_task(cron_entry, previously_at: nil)
87
+ cron_at = cron_entry.next_at(previously_at: previously_at)
87
88
  delay = [(cron_at - Time.current).to_f, 0].max
88
89
  future = Concurrent::ScheduledTask.new(delay, args: [self, cron_entry, cron_at], executor: @executor) do |thr_scheduler, thr_cron_entry, thr_cron_at|
89
90
  # Re-schedule the next cron task before executing the current task
90
- thr_scheduler.create_task(thr_cron_entry)
91
+ thr_scheduler.create_task(thr_cron_entry, previously_at: thr_cron_at)
91
92
 
92
93
  Rails.application.executor.wrap do
93
94
  cron_entry.enqueue(thr_cron_at) if thr_cron_entry.enabled?
@@ -2,7 +2,7 @@
2
2
 
3
3
  module GoodJob
4
4
  # GoodJob gem version.
5
- VERSION = '3.17.3'
5
+ VERSION = '3.18.0'
6
6
 
7
7
  # GoodJob version as Gem::Version object
8
8
  GEM_VERSION = Gem::Version.new(VERSION)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: good_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.17.3
4
+ version: 3.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Sheldon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-19 00:00:00.000000000 Z
11
+ date: 2023-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob