Class: Breaktime::Schedule

Inherits:
Object
  • Object
show all
Defined in:
lib/breaktime/schedule.rb

Overview

Schedule the running of the breaktime dialog and screensaver.

Uses rufus-scheduler to schedule the task running.

Instance Method Summary collapse

Constructor Details

#initialize(interval, days, cli_options, log) ⇒ Schedule

Returns a new instance of Schedule.



7
8
9
10
11
12
# File 'lib/breaktime/schedule.rb', line 7

def initialize(interval, days, cli_options, log)
  @interval = interval.to_s + 'm'
  @cli_options = cli_options
  @days = days
  @log = log
end

Instance Method Details

#startObject

Start the scheduler to run at a given interval.

The interval (60 minutes by default) can be set in the configuration YAML file. The days at which breaktime runs can also be set.

When it’s time to run, ‘run_dialog()` is called.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/breaktime/schedule.rb', line 20

def start
  scheduler = Rufus::Scheduler.start_new

  @log.info { "Taking a break every #{@interval}" }

  scheduler.every @interval do
    t = Time.now
    # Check whether the current day is included in the list
    if @days.detect {|d| t.send(d + '?')}
      @log.info { "Starting 10 second warning..." }
      run_dialog
    else
      @log.info { "Not running breaktime today" }
    end
  end

  scheduler.join
end