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, **opts) ⇒ Object
Class-level shorthand: 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{iso8601 => 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.
37 38 39 |
# File 'lib/wurk/deploy.rb', line 37 def initialize(pool: nil) @pool = pool end |
Class Method Details
.mark!(label = nil, at: ::Time.now, **opts) ⇒ Object
Class-level shorthand: builds a one-shot Deploy and delegates. Sidekiq's
Sidekiq::Deploy.mark! takes a POSITIONAL label (spec §23,
def self.mark!(label = nil)) — capistrano-sidekiq and custom deploy
hooks call Sidekiq::Deploy.mark!("abc123 release") that way. The **opts
also absorbs the label: keyword so Wurk's own keyword callers keep
working; positional wins when both are given.
33 34 35 |
# File 'lib/wurk/deploy.rb', line 33 def self.mark!(label = nil, at: ::Time.now, **opts) new.mark!(label: label.nil? ? opts[:label] : label, at: at) end |
Instance Method Details
#fetch(date = ::Time.now.utc) ⇒ Object
Returns the deploy marks for date (Date or Time) as {iso8601 => label}.
54 55 56 57 58 |
# File 'lib/wurk/deploy.rb', line 54 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).
44 45 46 47 48 49 50 51 |
# File 'lib/wurk/deploy.rb', line 44 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 |