Class: Wurk::Deploy
- Inherits:
-
Object
- Object
- Wurk::Deploy
- Defined in:
- lib/wurk/deploy.rb
Overview
Records deploy markers into Redis so the history pane can overlay “deployed at” lines onto job-throughput charts. Wire-compatible with Sidekiq’s ‘Sidekiq::Deploy`:
<YYYYMMDD>-marks HASH fields = iso8601 timestamp (rounded to minute),
values = label string, TTL = 90 days
deploylock-<label> STRING SET NX EX 60, dedupe lock for same-label marks
The lock collapses multiple ‘mark!` calls for the same label inside a 60-second window into a single HSET — fleet-wide deploys where every process calls `Wurk::Deploy.mark!` at boot end up with one row, not N.
Spec: docs/target/sidekiq-free.md §23.
Constant Summary collapse
- MARK_TTL =
90 days
90 * 24 * 60 * 60
- LOCK_TTL =
1 minute dedupe window
60- LOCK_PREFIX =
'deploylock-'- MARKS_SUFFIX =
'-marks'- LABEL_MAKER =
Default label maker: short git SHA + commit subject. Same shape as Sidekiq Pro’s LABEL_MAKER so existing deploy hooks keep working.
-> { `git log -1 --format="%h %s"`.strip }
Class Method Summary collapse
-
.mark!(label: nil, at: ::Time.now) ⇒ Object
Class-level shorthand ‘Wurk::Deploy.mark!(label: “abc”)` builds a one-shot Deploy and delegates.
Instance Method Summary collapse
-
#fetch(date = ::Time.now.utc) ⇒ Object
Returns the deploy marks for ‘date` (Date or Time) as `=> label`.
-
#initialize(pool: nil) ⇒ Deploy
constructor
A new instance of Deploy.
-
#mark!(label: nil, at: ::Time.now) ⇒ Object
Writes a deploy marker.
Constructor Details
#initialize(pool: nil) ⇒ Deploy
Returns a new instance of Deploy.
33 34 35 |
# File 'lib/wurk/deploy.rb', line 33 def initialize(pool: nil) @pool = pool end |
Class Method Details
.mark!(label: nil, at: ::Time.now) ⇒ Object
Class-level shorthand ‘Wurk::Deploy.mark!(label: “abc”)` builds a one-shot Deploy and delegates. Matches Sidekiq’s ‘Sidekiq::Deploy.mark!`.
29 30 31 |
# File 'lib/wurk/deploy.rb', line 29 def self.mark!(label: nil, at: ::Time.now) new.mark!(label: label, at: at) end |
Instance Method Details
#fetch(date = ::Time.now.utc) ⇒ Object
Returns the deploy marks for ‘date` (Date or Time) as `=> label`.
50 51 52 53 54 |
# File 'lib/wurk/deploy.rb', line 50 def fetch(date = ::Time.now.utc) date = date.utc if date.respond_to?(:utc) key = "#{date.strftime('%Y%m%d')}#{MARKS_SUFFIX}" with_redis { |c| c.call('HGETALL', key) } || {} end |
#mark!(label: nil, at: ::Time.now) ⇒ Object
Writes a deploy marker. Returns the iso8601 timestamp written, or ‘nil` when the per-label lock was already held (a previous process within the last 60 seconds beat us to it for the same label).
40 41 42 43 44 45 46 47 |
# File 'lib/wurk/deploy.rb', line 40 def mark!(label: nil, at: ::Time.now) label = resolve_label(label) return nil if label.nil? || label.empty? ts = round_to_minute(at) iso = ts.iso8601 write_mark?(label, ts, iso) ? iso : nil end |