Class: Lazylead::Schedule
- Inherits:
-
Object
- Object
- Lazylead::Schedule
- 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
-
#initialize(log = Log.new, cling = true) ⇒ Schedule
constructor
A new instance of Schedule.
- #join ⇒ Object
- #ps ⇒ Object
- #register(task) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(log = Log.new, cling = true) ⇒ Schedule
#/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.new, cling = true) @log = log @cling = cling @trigger = Rufus::Scheduler.new end |
Instance Method Details
#join ⇒ Object
65 66 67 |
# File 'lib/lazylead/schedule.rb', line 65 def join @trigger.join if @cling end |
#ps ⇒ Object
#/DEV inspect the current execution status. This method should support several format for output, by default is ‘json`.
63 |
# File 'lib/lazylead/schedule.rb', line 63 def ps; end |
#register(task) ⇒ Object
#/DEV error code is required for reach ‘raise’ statement within the application.
51 52 53 54 55 56 57 58 59 |
# 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 ActiveRecord::Base.connection_pool.with_connection do ORM::VerboseTask.new(task, @log).exec end end @log.debug "Task scheduled: #{task}" end |
#stop ⇒ Object
#/DEV stop the execution of current jobs (shutdown?). The test is required.
71 72 73 |
# File 'lib/lazylead/schedule.rb', line 71 def stop @trigger.shutdown(:kill) end |