Class: RCron::Task
- Inherits:
-
Object
- Object
- RCron::Task
- Defined in:
- lib/rcron/task.rb
Defined Under Namespace
Classes: TaskThread
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Name of the task.
-
#rcron ⇒ Object
readonly
RCron scheduler for this task.
-
#schedule ⇒ Object
readonly
Parsed cron schedule.
-
#schedule_expression ⇒ Object
readonly
Cron schedule expression.
-
#timeout ⇒ Object
readonly
Timeout for the task.
Instance Method Summary collapse
-
#deq ⇒ Object
(also: #dq)
Removes the task from the scheduler.
-
#exclusive? ⇒ Boolean
Returns whether if the same task should not run simultaneously.
-
#queued? ⇒ Boolean
Returns if the task is queued to the scheduler.
-
#run ⇒ Object
Executes the task manually.
-
#running? ⇒ Boolean
Returns if the task is being executed by one or more threads.
-
#scheduled?(at) ⇒ Boolean
Returns if the task is supposed to be triggered at the given moment.
-
#threads ⇒ Object
Threads running this task.
Instance Attribute Details
#name ⇒ Object (readonly)
Name of the task
10 11 12 |
# File 'lib/rcron/task.rb', line 10 def name @name end |
#rcron ⇒ Object (readonly)
RCron scheduler for this task
7 8 9 |
# File 'lib/rcron/task.rb', line 7 def rcron @rcron end |
#schedule ⇒ Object (readonly)
Parsed cron schedule
16 17 18 |
# File 'lib/rcron/task.rb', line 16 def schedule @schedule end |
#schedule_expression ⇒ Object (readonly)
Cron schedule expression
13 14 15 |
# File 'lib/rcron/task.rb', line 13 def schedule_expression @schedule_expression end |
#timeout ⇒ Object (readonly)
Timeout for the task
19 20 21 |
# File 'lib/rcron/task.rb', line 19 def timeout @timeout end |
Instance Method Details
#deq ⇒ Object Also known as: dq
Removes the task from the scheduler
56 57 58 59 |
# File 'lib/rcron/task.rb', line 56 def deq @queued = false nil end |
#exclusive? ⇒ Boolean
Returns whether if the same task should not run simultaneously
45 46 47 |
# File 'lib/rcron/task.rb', line 45 def exclusive? @exclusive end |
#queued? ⇒ Boolean
Returns if the task is queued to the scheduler
51 52 53 |
# File 'lib/rcron/task.rb', line 51 def queued? @queued end |
#run ⇒ Object
Executes the task manually
27 28 29 30 31 32 33 |
# File 'lib/rcron/task.rb', line 27 def run if @block.arity >= 1 @block.call self else @block.call end end |
#running? ⇒ Boolean
Returns if the task is being executed by one or more threads
37 38 39 40 41 |
# File 'lib/rcron/task.rb', line 37 def running? @mutex.synchronize { return @threads.empty? == false } end |
#scheduled?(at) ⇒ Boolean
Returns if the task is supposed to be triggered at the given moment.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rcron/task.rb', line 65 def scheduled? at if @previous_start.nil? || (at - at.sec).to_i > (@previous_start - @previous_start.sec).to_i s, m, h, day, mon, year, wd = at.to_a td = Date.new(year, mon, day) # at.to_date # Doesn't work with current JRuby wom = ((td - td.day + 1).wday + td.day - 1) / 7 + 1 last_day = (td + 1).month > td.month (@schedule[:years].nil? || @schedule[:years].has_key?(year)) && (@schedule[:months].nil? || @schedule[:months].has_key?(mon)) && (@schedule[:weekdays].nil? || [true, wom].include?(@schedule[:weekdays][wd])) && (@schedule[:days].nil? || @schedule[:days].has_key?(day) || (last_day && @schedule[:days].has_key?(-1)) ) && (@schedule[:hours].nil? || @schedule[:hours].has_key?(h)) && (@schedule[:minutes].nil? || @schedule[:minutes].has_key?(m)) else false end end |
#threads ⇒ Object
Threads running this task
22 23 24 |
# File 'lib/rcron/task.rb', line 22 def threads @mutex.synchronize { return @threads.dup } end |