diff options
author | Shinya Maeda <gitlab.shinyamaeda@gmail.com> | 2017-03-22 21:54:49 +0300 |
---|---|---|
committer | Shinya Maeda <gitlab.shinyamaeda@gmail.com> | 2017-04-06 17:46:58 +0300 |
commit | 5f715f1d32c6f5ce25b3721bde8f476173afadc8 (patch) | |
tree | aae1982a02c2c53c0da9229154e45b6fecb01f61 /lib | |
parent | 46e4ed6bd0c8c256bce6d35b4bb992d77fd09971 (diff) |
Add scheduled_trigger model. Add cron parser. Plus, specs.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ci/cron_parser.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/ci/cron_parser.rb b/lib/ci/cron_parser.rb new file mode 100644 index 00000000000..163cfc86aa7 --- /dev/null +++ b/lib/ci/cron_parser.rb @@ -0,0 +1,30 @@ +require 'rufus-scheduler' # Included in sidekiq-cron + +module Ci + class CronParser + def initialize(cron, cron_time_zone = 'UTC') + @cron = cron + @cron_time_zone = cron_time_zone + end + + def next_time_from_now + cronLine = try_parse_cron + return nil unless cronLine.present? + cronLine.next_time + end + + def valid_syntax? + try_parse_cron.present? ? true : false + end + + private + + def try_parse_cron + begin + Rufus::Scheduler.parse("#{@cron} #{@cron_time_zone}") + rescue + nil + end + end + end +end |