Sha256: ae97a7f4bec27a623a8551170ef972773ef4a5b90245ff0388a01f1b8d579f9e

Contents?: true

Size: 748 Bytes

Versions: 13

Compression:

Stored size: 748 Bytes

Contents

class Marty::CronJob < ActiveJob::Base
  class << self
    def schedule
      return reschedule if scheduled?

      cron = cron_expression

      return if cron.blank?

      set(cron: cron).perform_later
    end

    def reschedule
      dj = delayed_job
      return dj.update(cron: cron_expression) if dj.locked_by?

      remove
      schedule
    end

    def remove
      delayed_job.destroy if scheduled?
    end

    alias remove_schedule remove

    def scheduled?
      delayed_job.present?
    end

    def delayed_job
      Delayed::Job.
        where('handler LIKE ?', "%job_class: #{name}\n%").
        first
    end

    def cron_expression
      ::Marty::BackgroundJob::Schedule.on.find_by(job_class: name)&.cron
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
marty-5.1.4 app/jobs/marty/cron_job.rb
marty-5.1.3 app/jobs/marty/cron_job.rb
marty-5.1.2 app/jobs/marty/cron_job.rb
marty-5.1.1 app/jobs/marty/cron_job.rb
marty-5.1.0 app/jobs/marty/cron_job.rb
marty-3.1.0 app/jobs/marty/cron_job.rb
marty-3.0.1 app/jobs/marty/cron_job.rb
marty-4.0.0.rc2 app/jobs/marty/cron_job.rb
marty-3.0.0 app/jobs/marty/cron_job.rb
marty-2.9.3 app/jobs/marty/cron_job.rb
marty-2.9.2 app/jobs/marty/cron_job.rb
marty-2.9.1 app/jobs/marty/cron_job.rb
marty-2.8.0 app/jobs/marty/cron_job.rb