Class: AwsCron::CronRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_cron/runner.rb

Overview

Cron runner that runs a schedule based on provided time_provider You should avoid using this class directly

Instance Method Summary collapse

Constructor Details

#initialize(cron_str, time_provider = Time, leniency_secs = 30*60) ⇒ CronRunner



8
9
10
11
12
# File 'lib/aws_cron/runner.rb', line 8

def initialize(cron_str, time_provider=Time, leniency_secs=30*60)
  @cron = ::CronParser.new(cron_str, time_provider)
  @time_provider = time_provider
  @leniency_secs = leniency_secs
end

Instance Method Details

#run(time = @time_provider.now, &block) ⇒ Object



14
15
16
17
18
# File 'lib/aws_cron/runner.rb', line 14

def run(time=@time_provider.now, &block)
  if should_run(time)
    yield
  end
end

#should_run(time) ⇒ Object



20
21
22
23
24
# File 'lib/aws_cron/runner.rb', line 20

def should_run(time)
  last_execution_time = @cron.last(time)

  time >= last_execution_time - @leniency_secs && time < last_execution_time + @leniency_secs
end