Class: Scheduler::SchedulerTask
- Inherits:
-
Object
- Object
- Scheduler::SchedulerTask
- Defined in:
- lib/scheduler_daemon/scheduler_task.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#daemon_scheduler ⇒ Object
Returns the value of attribute daemon_scheduler.
-
#rufus_scheduler ⇒ Object
Returns the value of attribute rufus_scheduler.
Class Method Summary collapse
- .add_to(schedule) ⇒ Object
-
.at(*args) ⇒ Object
run the task at…
-
.cron(*args) ⇒ Object
run the task cron ‘* 4 * * *’, etc.
-
.environments(*args) ⇒ Object
what environments should this task run in? accepts the usual :development, :production, as well as :all.
-
.every(*args) ⇒ Object
run the task every…
-
.in(*args) ⇒ Object
run the task in ‘30s’, etc.
- .should_run_in_current_environment?(env) ⇒ Boolean
Instance Method Summary collapse
- #log(*args) ⇒ Object (also: #puts)
-
#run ⇒ Object
override me to do stuff.
Instance Attribute Details
#daemon_scheduler ⇒ Object
Returns the value of attribute daemon_scheduler.
3 4 5 |
# File 'lib/scheduler_daemon/scheduler_task.rb', line 3 def daemon_scheduler @daemon_scheduler end |
#rufus_scheduler ⇒ Object
Returns the value of attribute rufus_scheduler.
3 4 5 |
# File 'lib/scheduler_daemon/scheduler_task.rb', line 3 def rufus_scheduler @rufus_scheduler end |
Class Method Details
.add_to(schedule) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/scheduler_daemon/scheduler_task.rb', line 5 def add_to(schedule) %w(every in at cron).each{|time_cmd| if args = self.instance_variable_get("@#{time_cmd}") # add a default tag to the arguments so we know which task was running = args. .merge!(:tags => [name]) args << schedule.send(time_cmd, *args) do begin a_task = new a_task.daemon_scheduler = schedule.daemon_scheduler a_task.rufus_scheduler = schedule a_task.run ensure # Note: AR's ActiveRecord::Base.connection_pool.with_connection(&block) seems broken; # it doesn't release the connection properly. ActiveRecord::Base.connection_pool.release_connection end end end } end |
.at(*args) ⇒ Object
run the task at… Cronic.parse(‘5 pm’), etc. see rufus-scheduler docs
40 41 42 |
# File 'lib/scheduler_daemon/scheduler_task.rb', line 40 def at(*args) @at = args end |
.cron(*args) ⇒ Object
run the task cron ‘* 4 * * *’, etc. see rufus-scheduler docs
45 46 47 |
# File 'lib/scheduler_daemon/scheduler_task.rb', line 45 def cron(*args) @cron = args end |
.environments(*args) ⇒ Object
what environments should this task run in? accepts the usual :development, :production, as well as :all
examples:
environments :all
environments :staging, :production
environments :development
57 58 59 |
# File 'lib/scheduler_daemon/scheduler_task.rb', line 57 def environments(*args) @environments = args.map{|arg| arg.to_sym } end |
.every(*args) ⇒ Object
run the task every… ‘5m’, etc. see rufus-scheduler docs
30 31 32 |
# File 'lib/scheduler_daemon/scheduler_task.rb', line 30 def every(*args) @every = args end |
.in(*args) ⇒ Object
run the task in ‘30s’, etc. see rufus-scheduler docs
35 36 37 |
# File 'lib/scheduler_daemon/scheduler_task.rb', line 35 def in(*args) @in = args end |
.should_run_in_current_environment?(env) ⇒ Boolean
61 62 63 |
# File 'lib/scheduler_daemon/scheduler_task.rb', line 61 def should_run_in_current_environment?(env) @environments.nil? || @environments == [:all] || @environments.include?(env.to_sym) end |
Instance Method Details
#log(*args) ⇒ Object Also known as: puts
71 72 73 |
# File 'lib/scheduler_daemon/scheduler_task.rb', line 71 def log(*args) daemon_scheduler.log(*args) end |
#run ⇒ Object
override me to do stuff
67 68 69 |
# File 'lib/scheduler_daemon/scheduler_task.rb', line 67 def run nil end |