Skip to content

Commit

Permalink
Replace parse-cron with fugit
Browse files Browse the repository at this point in the history
parse-cron seems to be unmaintained since 2016, fugit seems to be still
active. In addition to that, it should also allow expressing intervals
such as "first Monday each month" which wasn't possible with parse-cron.
  • Loading branch information
adamruzicka committed Mar 1, 2023
1 parent a773406 commit a58cab8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions app/models/foreman_tasks/recurring_logic.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ForemanTasks
require 'parse-cron'
require 'fugit'

class RecurringLogic < ApplicationRecord
include Authorizable
Expand Down Expand Up @@ -96,11 +96,11 @@ def cancel
end

def next_occurrence_time(time = Time.zone.now)
@parser ||= CronParser.new(cron_line, Time.zone)
@parser ||= Fugit.parse_cron(cron_line)
# @parser.next(start_time) is not inclusive of the start_time hence stepping back one run to include checking start_time for the first run.
before_next = @parser.next(@parser.last(time.in_time_zone))
return before_next if before_next >= time && tasks.count == 0
@parser.next(time)
before_next = @parser.next_time(@parser.previous_time(time.iso8601))
return before_next.utc.localtime if before_next >= time && tasks.count == 0
@parser.next_time(time).utc.localtime
end

def generate_delay_options(time = Time.zone.now, options = {})
Expand Down
2 changes: 1 addition & 1 deletion foreman-tasks.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ same resource. It also optionally provides Dynflow infrastructure for using it f
s.extra_rdoc_files = Dir['README*', 'LICENSE']

s.add_dependency "dynflow", '>= 1.6.0'
s.add_dependency 'fugit', '~> 1.8.1'
s.add_dependency "get_process_mem" # for memory polling
s.add_dependency "parse-cron", '~> 0.1.4'
s.add_dependency "sinatra" # for Dynflow web console

s.add_development_dependency 'factory_bot_rails', '~> 4.8.0'
Expand Down

0 comments on commit a58cab8

Please sign in to comment.