cogworker 0.5.1 → 0.6.0

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: fa6ea3cf9620f3c099c39fe6bba306cd78b037e8c0c7c8dab161586c98d1081f
4
- data.tar.gz: b0b58c6118437e59c6748202ef21a8980ed22f916f27ed14ec3179de8bb435e0
3
+ metadata.gz: 2a2d6b5721f03a71d8a74d376311c047175b71f950d51f227c60598dad74dce2
4
+ data.tar.gz: d6f10624306849c6e32e8d7fa0211db6c2b947d78d53fec10b79039bfec57645
5
5
  SHA512:
6
- metadata.gz: ce3267edd66d5fcab03aec48a0ae8b3fbeb749a1c4e7db298158387c9fd7a8c6f7332dee99ed1b91499bc9c0b87f748dfb966c274b55ad6e643e76afbf5d57d9
7
- data.tar.gz: d1706f96404137a3594ca6182988a10c990f77a15b4f5aa0a2f2e758eab6dcc4815f88a9c6ac5aada117bfe3f5660df93e489b9df311460c5d7d2829e76868d4
6
+ metadata.gz: 97347577fddf8a44cc0c5df6b6aafd5a60c285f88f58f7c09193f8a1031d5bf9dc0381e2708a9d591ff81dde7781b31be6a72f7d7567b9f2a0a8b74fb0de2658
7
+ data.tar.gz: 84ea3a607e75d78b23dab9919c33595ade3ac2382c2c253896a6e3b4df7664d8369fbd1b81a387eaaa9ae95fe3867dd8739ce7d757a0e576047f51321e78cd5e
data/README.md CHANGED
@@ -363,6 +363,18 @@ about two minutes after the process's last heartbeat (7 minutes by default).
363
363
  On first start against an empty Redis, each entry's most recent due slot
364
364
  fires right away. To turn that off, set `config.periodic_catch_up = false`.
365
365
 
366
+ Entries are only ever added to the published schedule (what the Schedules
367
+ tab shows), so one removed from your code stays listed there. Pass
368
+ `replace: true` to clear what was registered before and replace the
369
+ published schedule with exactly this set on every boot:
370
+
371
+ ```ruby
372
+ config.periodic(replace: true, &PERIODIC_JOBS)
373
+ ```
374
+
375
+ Don't use it if different processes register different schedules against
376
+ the same Redis — each would erase the others' entries from the tab.
377
+
366
378
  ## Job status
367
379
 
368
380
  ```ruby
@@ -9,7 +9,7 @@ module Cogworker
9
9
  FETCH_MODES = %i[reliable basic].freeze
10
10
 
11
11
  attr_reader :server_chain, :client_chain, :periodic_manager, :redis_options, :fetch, :fetch_idle_max_interval,
12
- :orphan_threshold, :max_orphanings
12
+ :orphan_threshold, :max_orphanings, :periodic_replace
13
13
  attr_accessor :concurrency, :queues, :periodic_catch_up, :unique_lock_ttl
14
14
 
15
15
  def initialize
@@ -133,7 +133,18 @@ module Cogworker
133
133
  # registers cron entries synchronously as it runs. No-op-safe: an app
134
134
  # that never calls this simply has an empty periodic_manager, and the
135
135
  # Ticker (started later, per process) has nothing to do.
136
- def periodic(&block)
136
+ #
137
+ # `replace: true` clears what earlier calls registered first, and makes
138
+ # the Ticker replace the whole published `periodic:schedule` rather than
139
+ # adding to it — so an entry deleted from (or changed in) the schedule
140
+ # file disappears from the Web UI instead of lingering there forever.
141
+ # Opt-in: with processes that register *different* schedules against one
142
+ # Redis, each would wipe the others' entries off the Schedules tab.
143
+ def periodic(replace: false, &block)
144
+ if replace
145
+ periodic_manager.clear!
146
+ @periodic_replace = true
147
+ end
137
148
  block&.call(periodic_manager)
138
149
  periodic_manager
139
150
  end
@@ -21,6 +21,7 @@ module Cogworker
21
21
  # two runs at once.
22
22
  @ticker = Periodic::Ticker.new(
23
23
  @manager, config.periodic_manager.entries, catch_up: config.periodic_catch_up,
24
+ replace: config.periodic_replace,
24
25
  ready: -> { @scheduled.ready_for_ticker? }
25
26
  )
26
27
  @signal_queue = ::Queue.new
@@ -23,6 +23,11 @@ module Cogworker
23
23
  @entries << entry
24
24
  entry
25
25
  end
26
+
27
+ # In place: Launcher hands this same `entries` array to the Ticker.
28
+ def clear!
29
+ @entries.clear
30
+ end
26
31
  end
27
32
  end
28
33
  end
@@ -46,10 +46,11 @@ module Cogworker
46
46
  return 1
47
47
  LUA
48
48
 
49
- def initialize(manager, entries, catch_up: true, ready: -> { true })
49
+ def initialize(manager, entries, catch_up: true, replace: false, ready: -> { true })
50
50
  @manager = manager
51
51
  @entries = entries
52
52
  @catch_up = catch_up
53
+ @replace = replace
53
54
  @ready = ready
54
55
  @last_checked_slot = {}
55
56
  @cron_cache = {}
@@ -84,8 +85,12 @@ module Cogworker
84
85
  # here (not at DSL-registration time in Config#periodic) so it never
85
86
  # depends on `config.redis =` having already run — every process that
86
87
  # boots re-writes the same idempotent entries regardless of ordering.
88
+ # With `replace` (Config#periodic(replace: true)) the hash is swapped
89
+ # out wholesale in one MULTI, dropping entries no longer registered
90
+ # (their `last_slot`/`disabled` state is left alone: an old process
91
+ # still ticking them mid-deploy must not re-fire an already-run slot).
87
92
  def publish_schedule!
88
- return if @entries.empty?
93
+ return if @entries.empty? && !@replace
89
94
 
90
95
  payloads = @entries.each_with_object({}) do |entry, h|
91
96
  h[entry.pjid] = JSON.generate(
@@ -93,7 +98,14 @@ module Cogworker
93
98
  'unique' => entry.unique, 'args' => entry.args
94
99
  )
95
100
  end
96
- Cogworker.config.redis { |c| c.hset(RedisKeys::PERIODIC_SCHEDULE, *payloads.to_a.flatten) }
101
+ Cogworker.config.redis do |c|
102
+ next c.hset(RedisKeys::PERIODIC_SCHEDULE, *payloads.to_a.flatten) unless @replace
103
+
104
+ c.multi do |tx|
105
+ tx.del(RedisKeys::PERIODIC_SCHEDULE)
106
+ tx.hset(RedisKeys::PERIODIC_SCHEDULE, *payloads.to_a.flatten) unless payloads.empty?
107
+ end
108
+ end
97
109
  end
98
110
 
99
111
  # A failed tick is logged and retried next interval rather than ending
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cogworker
4
- VERSION = '0.5.1'
4
+ VERSION = '0.6.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cogworker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - vdonec