Class: Scheduler::SchedulerTask

Inherits:
Object
  • Object
show all
Defined in:
lib/scheduler_daemon/scheduler_task.rb

Direct Known Subclasses

SessionCleanerTask

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#daemon_schedulerObject

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_schedulerObject

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
      options = args.extract_options!
      options.merge!(:tags => [name])
      args << options

      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

Returns:

  • (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

#runObject

override me to do stuff



67
68
69
# File 'lib/scheduler_daemon/scheduler_task.rb', line 67

def run
  nil
end