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 +4 -4
- data/README.md +12 -0
- data/lib/cogworker/config.rb +13 -2
- data/lib/cogworker/launcher.rb +1 -0
- data/lib/cogworker/periodic/manager.rb +5 -0
- data/lib/cogworker/periodic/ticker.rb +15 -3
- data/lib/cogworker/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2a2d6b5721f03a71d8a74d376311c047175b71f950d51f227c60598dad74dce2
|
|
4
|
+
data.tar.gz: d6f10624306849c6e32e8d7fa0211db6c2b947d78d53fec10b79039bfec57645
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
data/lib/cogworker/config.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
data/lib/cogworker/launcher.rb
CHANGED
|
@@ -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
|
|
@@ -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
|
|
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
|
data/lib/cogworker/version.rb
CHANGED