mirror of
https://github.com/plashchynski/crono.git
synced 2026-03-24 02:11:39 +01:00
26 lines
529 B
Ruby
26 lines
529 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 { performer.new.perform }
|
|
end
|
|
end
|
|
end
|