Class: Lazylead::Schedule

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

Overview

The tasks schedule

Author

Yurii Dubinka ([email protected])

Copyright

Copyright © 2019-2020 Yurii Dubinka

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(log = Log::NOTHING, cling = true) ⇒ Schedule

TODO:

#/DEV New scheduling types like ‘at’, ‘once’ is required. The minimum time period for cron is 1 minute and it’s not suitable for unit testing, thus its better to introduce new types which allows to schedule some task once or at particular time period like in next 200ms). For cron expressions we should define separate test suite which will test in parallel without blocking main CI process.

Returns a new instance of Schedule.



43
44
45
46
47
# File 'lib/lazylead/schedule.rb', line 43

def initialize(log = Log::NOTHING, cling = true)
  @log = log
  @cling = cling
  @trigger = Rufus::Scheduler.new
end

Instance Method Details

#joinObject



63
64
65
# File 'lib/lazylead/schedule.rb', line 63

def join
  @trigger.join if @cling
end

#psObject

TODO:

#/DEV inspect the current execution status. This method should support several format for output, by default is ‘json`.



61
# File 'lib/lazylead/schedule.rb', line 61

def ps; end

#register(task) ⇒ Object

TODO:

#/DEV error code is required for reach ‘raise’ statement within the application.



51
52
53
54
55
56
57
# File 'lib/lazylead/schedule.rb', line 51

def register(task)
  raise "ll-002: task can't be a null" if task.nil?
  @trigger.cron task.cron do
    task.exec @log
  end
  @log.debug "Task scheduled: #{task}"
end

#stopObject

TODO:

#/DEV stop the execution of current jobs (shutdown?). The test is required.



69
70
71
# File 'lib/lazylead/schedule.rb', line 69

def stop
  @trigger.shutdown(:kill)
end