mirror of
https://github.com/plashchynski/crono.git
synced 2026-03-29 05:42:02 +02:00
29 lines
645 B
Ruby
29 lines
645 B
Ruby
module Crono
|
|
class Job
|
|
attr_accessor :performer
|
|
attr_accessor :period
|
|
attr_accessor :last_performed_at
|
|
|
|
def initialize(performer, period)
|
|
self.performer, self.period = performer, period
|
|
end
|
|
|
|
def next
|
|
period.next(since: last_performed_at)
|
|
end
|
|
|
|
def description
|
|
"Perform #{performer} #{period.description}"
|
|
end
|
|
|
|
def perform
|
|
Crono.logger.info "Perform #{performer}"
|
|
self.last_performed_at = Time.now
|
|
Thread.new do
|
|
performer.new.perform
|
|
Crono.logger.info "Finished #{performer} in %.2f seconds" % (Time.now - last_performed_at)
|
|
end
|
|
end
|
|
end
|
|
end
|