Нет описания http://j1x-huginn.herokuapp.com

scheduler_agent.rb 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. require 'rufus-scheduler'
  2. module Agents
  3. class SchedulerAgent < Agent
  4. include AgentControllerConcern
  5. cannot_be_scheduled!
  6. cannot_receive_events!
  7. cannot_create_events!
  8. description <<-MD
  9. This agent periodically triggers a run of each target Agent according to a user-defined schedule.
  10. Select target Agents and set a cron-style schedule to `schedule`.
  11. In the traditional cron format, a schedule part consists of these five columns: `minute hour day-of-month month day-of-week`.
  12. * `0 22 * * 1-5`: every day of the week at 22:00 (10pm)
  13. In this variant, you can also specify seconds:
  14. * `30 0 22 * * 1-5`: every day of the week at 22:00:30
  15. And timezones:
  16. * `0 22 * * 1-5 Europe/Paris`: every day of the week when it's 22:00 in Paris
  17. * `0 22 * * 1-5 Etc/GMT+2`: every day of the week when it's 22:00 in GMT+2
  18. There's also a way to specify "last day of month":
  19. * `0 22 L * *`: every month on the last day at 22:00
  20. And "monthdays":
  21. * `0 22 * * sun#1,sun#2`: every first and second sunday of the month, at 22:00
  22. * `0 22 * * sun#L1`: every last sunday of the month, at 22:00
  23. MD
  24. def default_options
  25. super.update({
  26. 'schedule' => '0 * * * *',
  27. })
  28. end
  29. def working?
  30. true
  31. end
  32. def check!
  33. control_targets!
  34. end
  35. def validate_options
  36. if (spec = options['schedule']).present?
  37. begin
  38. Rufus::Scheduler::CronLine.new(spec)
  39. rescue ArgumentError
  40. errors.add(:base, "invalid schedule")
  41. end
  42. else
  43. errors.add(:base, "schedule is missing")
  44. end
  45. end
  46. before_save do
  47. self.memory.delete('scheduled_at') if self.options_changed?
  48. end
  49. end
  50. end