Class: RCron::Task::TaskThread
- Inherits:
-
Object
- Object
- RCron::Task::TaskThread
- Defined in:
- lib/rcron/task.rb
Instance Attribute Summary collapse
-
#ended_at ⇒ Object
readonly
Returns the value of attribute ended_at.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #cleanup ⇒ Object
- #elapsed ⇒ Object
-
#initialize(task, started_at) ⇒ TaskThread
constructor
A new instance of TaskThread.
- #kill! ⇒ Object
Constructor Details
#initialize(task, started_at) ⇒ TaskThread
Returns a new instance of TaskThread.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/rcron/task.rb', line 137 def initialize task, started_at @started_at = started_at @thread = Thread.new { begin task.run @ended_at = Time.now task.rcron.send :info, "[#{task.name}] completed (#{'%.2f' % elapsed}s)" rescue Exception => e @ended_at = Time.now task.rcron.send :error, "[#{task.name}] terminated: #{[e, e.backtrace].join($/)}" # Ignore exception? end task.rcron.send :wake_up } end |
Instance Attribute Details
#ended_at ⇒ Object (readonly)
Returns the value of attribute ended_at.
134 135 136 |
# File 'lib/rcron/task.rb', line 134 def ended_at @ended_at end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
135 136 137 |
# File 'lib/rcron/task.rb', line 135 def exception @exception end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
134 135 136 |
# File 'lib/rcron/task.rb', line 134 def started_at @started_at end |
Instance Method Details
#alive? ⇒ Boolean
163 164 165 |
# File 'lib/rcron/task.rb', line 163 def alive? @thread.alive? end |
#cleanup ⇒ Object
155 156 157 |
# File 'lib/rcron/task.rb', line 155 def cleanup @thread.join end |
#elapsed ⇒ Object
159 160 161 |
# File 'lib/rcron/task.rb', line 159 def elapsed (@ended_at || Time.now) - @started_at end |