Module: DelayedCron

Extended by:
Scheduling
Defined in:
lib/delayed_cron.rb,
lib/delayed_cron/jobs.rb,
lib/delayed_cron/railtie.rb,
lib/delayed_cron/version.rb,
lib/delayed_cron/cron_job.rb,
lib/delayed_cron/scheduling.rb,
lib/delayed_cron/jobs/resque.rb,
lib/delayed_cron/jobs/sidekiq.rb,
lib/delayed_cron/jobs/delayed_job.rb,
lib/delayed_cron/jobs/sucker_punch.rb

Defined Under Namespace

Modules: ClassMethods, Glue, Jobs, Scheduling Classes: CronJob, Railtie

Constant Summary collapse

VERSION =
"0.2.11"

Class Method Summary collapse

Methods included from Scheduling

schedule, timing_opts

Class Method Details

.default_time_zoneObject



45
46
47
# File 'lib/delayed_cron.rb', line 45

def default_time_zone
  @@default_time_zone || "Eastern Time (US & Canada)"
end

.define_cron_jobsObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/delayed_cron.rb', line 19

def define_cron_jobs
  return false unless cron_jobs.present?

  cron_jobs.each do |job|
    job = job.is_a?(Hash) ? job : { job: job }
    klass, name = job[:job].split(".")
    # TODO: raise error if interval is not set
    options     = timing_opts(job)
    DelayedCron.schedule(klass, name, options)
  end
end

.process_job(klass, method_name, options) ⇒ Object



38
39
40
41
42
43
# File 'lib/delayed_cron.rb', line 38

def process_job(klass, method_name, options)
  # TODO: add ability to send args to klass method
  klass.constantize.send(method_name)
  symbolized_options = options.collect{|k,v| [k.to_sym, v]}.to_h
  schedule(klass, method_name, symbolized_options)
end

.processorObject



31
32
33
34
35
36
# File 'lib/delayed_cron.rb', line 31

def processor
  return DelayedCron::Jobs::DelayedJob  if defined? ::Delayed::Job
  return DelayedCron::Jobs::Resque      if defined? ::Resque
  return DelayedCron::Jobs::Sidekiq     if defined? ::Sidekiq
  return DelayedCron::Jobs::SuckerPunch if defined? ::SuckerPunch
end

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (DelayedCron)

    the object that the method was called on



14
15
16
17
# File 'lib/delayed_cron.rb', line 14

def setup
  yield self
  define_cron_jobs
end