Module: Zhong
- Extended by:
- Forwardable
- Defined in:
- lib/zhong.rb,
lib/zhong/at.rb,
lib/zhong/job.rb,
lib/zhong/web.rb,
lib/zhong/util.rb,
lib/zhong/every.rb,
lib/zhong/version.rb,
lib/zhong/scheduler.rb,
lib/zhong/web_helpers.rb
Defined Under Namespace
Modules: Util, WebHelpers
Classes: At, Every, Job, MultiAt, Scheduler, Web
Constant Summary
collapse
- VERSION =
"0.1.7".freeze
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.logger ⇒ Object
50
51
52
53
54
|
# File 'lib/zhong.rb', line 50
def self.logger
@logger ||= Logger.new(STDOUT).tap do |logger|
logger.formatter = -> (_, datetime, _, msg) { "#{datetime}: #{msg}\n" }
end
end
|
.redis ⇒ Object
56
57
58
|
# File 'lib/zhong.rb', line 56
def self.redis
@redis ||= Redis.new(url: ENV["REDIS_URL"])
end
|
.tz ⇒ Object
Returns the value of attribute tz.
22
23
24
|
# File 'lib/zhong.rb', line 22
def tz
@tz
end
|
Class Method Details
.all_heartbeats ⇒ Object
43
44
45
46
47
48
|
# File 'lib/zhong.rb', line 43
def self.all_heartbeats
Zhong::Util.safe_mget(Zhong.redis.scan_each(match: "zhong:heartbeat:*").to_a).map do |k, v|
host, pid = k.split("zhong:heartbeat:", 2)[1].split("#", 2)
{host: host, pid: pid, last_seen: Time.at(v.to_i)}
end
end
|
.any_running?(grace = 60.seconds) ⇒ Boolean
35
36
37
|
# File 'lib/zhong.rb', line 35
def self.any_running?(grace = 60.seconds)
latest_heartbeat > (redis_time - grace)
end
|
.latest_heartbeat ⇒ Object
39
40
41
|
# File 'lib/zhong.rb', line 39
def self.latest_heartbeat
all_heartbeats.map { |h| h[:last_seen] }.sort.last
end
|
.schedule(&block) ⇒ Object
27
28
29
|
# File 'lib/zhong.rb', line 27
def self.schedule(&block)
scheduler.instance_eval(&block) if block_given?
end
|
.scheduler ⇒ Object
31
32
33
|
# File 'lib/zhong.rb', line 31
def self.scheduler
@scheduler ||= Scheduler.new(logger: logger, redis: redis, tz: tz)
end
|