Sha256: c5306416517316b44703d92d867b784bba555164909146be7a8179738acb6c70

Contents?: true

Size: 868 Bytes

Versions: 1

Compression:

Stored size: 868 Bytes

Contents

require "digest"
require "logger"
require "msgpack"
require "redis"
require "suo"
require "active_support/time"

require "zhong/version"

require "zhong/every"
require "zhong/at"

require "zhong/job"
require "zhong/scheduler"

module Zhong
  class << self
    attr_writer :logger, :redis
    attr_accessor :tz
  end

  def self.schedule(&block)
    scheduler.instance_eval(&block) if block_given?
  end

  def self.start
    scheduler.start
  end

  def self.stop
    scheduler.stop
  end

  def self.scheduler
    @scheduler ||= Scheduler.new(logger: logger, redis: redis, tz: tz)
  end

  def self.jobs
    scheduler.jobs
  end

  def self.logger
    @logger ||= Logger.new(STDOUT).tap do |logger|
      logger.formatter = -> (_, datetime, _, msg) { "#{datetime}: #{msg}\n" }
    end
  end

  def self.redis
    @redis ||= Redis.new(url: ENV["REDIS_URL"])
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zhong-0.1.5 lib/zhong.rb