lib/sidekiq/cron/job.rb in sidekiq-cron-1.9.0 vs lib/sidekiq/cron/job.rb in sidekiq-cron-1.9.1

- old
+ new

@@ -54,11 +54,11 @@ nil end jid = if klass_const - if defined?(ActiveJob::Base) && klass_const < ActiveJob::Base + if is_active_job?(klass_const) enqueue_active_job(klass_const).try :provider_job_id else enqueue_sidekiq_worker(klass_const) end else @@ -72,12 +72,12 @@ save_last_enqueue_time add_jid_history jid Sidekiq.logger.debug { "enqueued #{@name}: #{@message}" } end - def is_active_job? - @active_job || defined?(ActiveJob::Base) && Sidekiq::Cron::Support.constantize(@klass.to_s) < ActiveJob::Base + def is_active_job?(klass = nil) + @active_job || defined?(ActiveJob::Base) && (klass || Sidekiq::Cron::Support.constantize(@klass.to_s)) < ActiveJob::Base rescue NameError false end def date_as_argument? @@ -426,19 +426,11 @@ errors << "'name' must be set" if @name.nil? || @name.size == 0 if @cron.nil? || @cron.size == 0 errors << "'cron' must be set" else begin - c = Fugit.do_parse(@cron) - - # Since `Fugit.do_parse` might yield a Fugit::Duration or an EtOrbi::EoTime - # https://github.com/floraison/fugit#fugitparses - if c.is_a?(Fugit::Cron) - @parsed_cron = c - else - errors << "'cron' -> #{@cron.inspect} -> not a cron but a #{c.class}" - end + @parsed_cron = Fugit.do_parse_cronish(@cron) rescue => e errors << "'cron' -> #{@cron.inspect} -> #{e.class}: #{e.message}" end end @@ -563,22 +555,10 @@ end private def parsed_cron - @parsed_cron ||= begin - c = Fugit.parse(@cron) - - # Since `Fugit.parse` might yield a Fugit::Duration or an EtOrbi::EoTime - # https://github.com/floraison/fugit#fugitparses - if c.is_a?(Fugit::Cron) - c - else - errors << "'cron' -> #{@cron.inspect} -> not a cron but a #{c.class}" - end - rescue => e - errors << "'cron' -> #{@cron.inspect} -> #{e.class}: #{e.message}" - end + @parsed_cron ||= Fugit.parse_cronish(@cron) end def not_enqueued_after?(time) @last_enqueue_time.nil? || @last_enqueue_time.to_i < last_time(time).to_i end