Class: SidekiqScheduler::JobPresenter

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::WebHelpers
Defined in:
lib/sidekiq-scheduler/job_presenter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, attributes) ⇒ JobPresenter

Returns a new instance of JobPresenter.



13
14
15
16
# File 'lib/sidekiq-scheduler/job_presenter.rb', line 13

def initialize(name, attributes)
  @name = name
  @attributes = attributes
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/sidekiq-scheduler/job_presenter.rb', line 9

def name
  @name
end

Class Method Details

.build_collection(schedule_hash) ⇒ Array<JobPresenter>

Builds the presenter instances for the schedule hash

Parameters:

  • schedule_hash (Hash)

    with the redis schedule

Returns:

  • (Array<JobPresenter>)

    an array with the instances of presenters



52
53
54
55
56
# File 'lib/sidekiq-scheduler/job_presenter.rb', line 52

def self.build_collection(schedule_hash)
  Hash(schedule_hash).map do |name, job_spec|
    new(name, job_spec)
  end
end

Instance Method Details

#[](key) ⇒ String

Delegates the :[] method to the attributes’ hash

Returns:

  • (String)

    with the value for that key



44
45
46
# File 'lib/sidekiq-scheduler/job_presenter.rb', line 44

def [](key)
  @attributes[key]
end

#intervalString

Returns the interval for the job

Returns:

  • (String)

    with the job’s interval



30
31
32
# File 'lib/sidekiq-scheduler/job_presenter.rb', line 30

def interval
  @attributes['cron'] || @attributes['interval'] || @attributes['every']
end

#next_timeString

Returns the next time execution for the job

Returns:

  • (String)

    with the job’s next time



21
22
23
24
25
# File 'lib/sidekiq-scheduler/job_presenter.rb', line 21

def next_time
  execution_time = Sidekiq.redis { |r| r.hget(Sidekiq::Scheduler.next_times_key, name) }

  relative_time(Time.parse(execution_time)) if execution_time
end

#queueString

Returns the queue of the job

Returns:

  • (String)

    with the job’s queue



37
38
39
# File 'lib/sidekiq-scheduler/job_presenter.rb', line 37

def queue
  @attributes.fetch('queue', 'default')
end