mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
29dca70e24
* Initial work on Sidekiq::Config * Initial work on Sidekiq::Config * reduce dependencies in deploy marks * bare sidekiq and webapp * Modify runtime to work with Capsules * Cleanup * Rename test files to remove test_ prefix * Update test suite and standard rules to be more compliant * Move constant definition outside code, per standard formatting * Loads of changes for introduction of Capsules * Remove Redis adapter abstraction * update capsule overview * Ensure Sidekiq.redis uses the correct pool for jobs running within a Capsule * Use default_capsule for safety * Slow down the beat to halve its Redis overhead * move config fixtures into cfg/ * Add capsule middleware test * use accessor
47 lines
1.5 KiB
Ruby
47 lines
1.5 KiB
Ruby
require "sidekiq/redis_connection"
|
|
require "time"
|
|
|
|
# This file is designed to be required within the user's
|
|
# deployment script; it should need a bare minimum of dependencies.
|
|
#
|
|
# require "sidekiq/metrics/deploy"
|
|
# gitdesc = `git log -1 --format="%h %s"`.strip
|
|
# d = Sidekiq::Metrics::Deploy.new
|
|
# d.mark(label: gitdesc)
|
|
#
|
|
# Note that you cannot mark more than once per minute. This is a feature, not a bug.
|
|
module Sidekiq
|
|
module Metrics
|
|
class Deploy
|
|
MARK_TTL = 90 * 24 * 60 * 60 # 90 days
|
|
|
|
def initialize(pool = Sidekiq::RedisConnection.create)
|
|
@pool = pool
|
|
end
|
|
|
|
def mark(at: Time.now, label: "")
|
|
# we need to round the timestamp so that we gracefully
|
|
# handle an excepted common error in marking deploys:
|
|
# having every process mark its deploy, leading
|
|
# to N marks for each deploy. Instead we round the time
|
|
# to the minute so that multple marks within that minute
|
|
# will all naturally rollup into one mark per minute.
|
|
whence = at.utc
|
|
floor = Time.utc(whence.year, whence.month, whence.mday, whence.hour, whence.min, 0)
|
|
datecode = floor.strftime("%Y%m%d")
|
|
key = "#{datecode}-marks"
|
|
@pool.with do |c|
|
|
c.pipelined do |pipe|
|
|
pipe.hsetnx(key, floor.iso8601, label)
|
|
pipe.expire(key, MARK_TTL)
|
|
end
|
|
end
|
|
end
|
|
|
|
def fetch(date = Time.now.utc.to_date)
|
|
datecode = date.strftime("%Y%m%d")
|
|
@pool.with { |c| c.hgetall("#{datecode}-marks") }
|
|
end
|
|
end
|
|
end
|
|
end
|