Module: Quartz::Scheduler::InstanceMethods

Defined in:
lib/quartz/scheduler.rb

Instance Method Summary collapse

Instance Method Details

#defaultsObject



48
49
50
51
52
# File 'lib/quartz/scheduler.rb', line 48

def defaults
  {
    :at=>0
  }
end

#job_factoryObject



59
60
61
# File 'lib/quartz/scheduler.rb', line 59

def job_factory
  JobFactory.instance
end

#runObject



62
63
64
# File 'lib/quartz/scheduler.rb', line 62

def run
  scheduler.start
end

#schedule(name, options, block) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/quartz/scheduler.rb', line 38

def schedule(name, options, block)
  options = defaults.merge options
  job_factory.jobs[name.to_s] = block
  job_detail = JobDetail.new(name.to_s, "cronjob", CronJob.new(name.to_s))
  at = Time.parse(options[:at]) rescue nil || options[:at]
  cron_expression = Cronify.cronify(options[:every], at)
  trigger = CronTrigger.new("#{name.to_s}_crontrig", "cront_trig_group", name.to_s, "cronjob", cron_expression)
  scheduler.set_job_factory(job_factory)
  scheduler.schedule_job(job_detail, trigger)
end

#schedulerObject



56
57
58
# File 'lib/quartz/scheduler.rb', line 56

def scheduler
  scheduler_factory.get_scheduler
end

#scheduler_factoryObject



53
54
55
# File 'lib/quartz/scheduler.rb', line 53

def scheduler_factory
  @scheduler_factor ||= StdSchedulerFactory.new
end