Sha256: a5299344d7ae908b78aebff8a075d6f03145ef49a8ef00a3646732767fdc9214

Contents?: true

Size: 760 Bytes

Versions: 62

Compression:

Stored size: 760 Bytes

Contents

module Workarea
  class Scheduler
    attr_reader :job_id

    def self.schedule(*args)
      instance = new(*args)
      instance.perform
      instance.job_id
    end

    def self.delete(job_id)
      new(job_id: job_id).delete
    end

    def initialize(options = {})
      @time = options[:at]
      @worker = options[:worker]
      @args = options[:args]
      @job_id = options[:job_id]
    end

    def perform
      delete
      add_job
    end

    def delete
      current_job.try(:delete)
    end

    def add_job
      @job_id = @worker.perform_at(@time, *@args)
    end

    private

    def current_job
      return nil if job_id.blank?

      @current_job ||=
        Sidekiq::ScheduledSet.new.detect { |j| j.jid == job_id }
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 lib/workarea/scheduler.rb
workarea-core-3.5.26 lib/workarea/scheduler.rb
workarea-core-3.4.45 lib/workarea/scheduler.rb
workarea-core-3.5.25 lib/workarea/scheduler.rb
workarea-core-3.5.23 lib/workarea/scheduler.rb
workarea-core-3.4.44 lib/workarea/scheduler.rb
workarea-core-3.5.22 lib/workarea/scheduler.rb
workarea-core-3.4.43 lib/workarea/scheduler.rb
workarea-core-3.5.21 lib/workarea/scheduler.rb
workarea-core-3.4.42 lib/workarea/scheduler.rb
workarea-core-3.5.20 lib/workarea/scheduler.rb
workarea-core-3.4.41 lib/workarea/scheduler.rb
workarea-core-3.5.19 lib/workarea/scheduler.rb
workarea-core-3.4.40 lib/workarea/scheduler.rb
workarea-core-3.5.18 lib/workarea/scheduler.rb
workarea-core-3.4.39 lib/workarea/scheduler.rb
workarea-core-3.5.17 lib/workarea/scheduler.rb
workarea-core-3.4.38 lib/workarea/scheduler.rb
workarea-core-3.5.16 lib/workarea/scheduler.rb
workarea-core-3.4.37 lib/workarea/scheduler.rb