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.4.27 lib/workarea/scheduler.rb
workarea-core-3.5.4 lib/workarea/scheduler.rb
workarea-core-3.4.26 lib/workarea/scheduler.rb
workarea-core-3.5.3 lib/workarea/scheduler.rb
workarea-core-3.4.25 lib/workarea/scheduler.rb
workarea-core-3.5.2 lib/workarea/scheduler.rb
workarea-core-3.4.24 lib/workarea/scheduler.rb
workarea-core-3.5.1 lib/workarea/scheduler.rb
workarea-core-3.4.23 lib/workarea/scheduler.rb
workarea-core-3.4.22 lib/workarea/scheduler.rb
workarea-core-3.5.0 lib/workarea/scheduler.rb
workarea-core-3.4.21 lib/workarea/scheduler.rb
workarea-core-3.5.0.beta.1 lib/workarea/scheduler.rb
workarea-core-3.4.20 lib/workarea/scheduler.rb
workarea-core-3.4.19 lib/workarea/scheduler.rb
workarea-core-3.4.18 lib/workarea/scheduler.rb
workarea-core-3.4.17 lib/workarea/scheduler.rb
workarea-core-3.4.16 lib/workarea/scheduler.rb
workarea-core-3.4.15 lib/workarea/scheduler.rb
workarea-core-3.4.14 lib/workarea/scheduler.rb