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.


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

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


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

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


66
67
68
69
70
71
72
# File 'lib/sidekiq-scheduler/job_presenter.rb', line 66

def self.build_collection(schedule_hash)
  schedule_hash ||= {}

  schedule_hash.sort.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


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

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

#enabled?Boolean

Returns:

  • (Boolean)

58
59
60
# File 'lib/sidekiq-scheduler/job_presenter.rb', line 58

def enabled?
  SidekiqScheduler::Scheduler.job_enabled?(@name)
end

#intervalString

Returns the interval for the job

Returns:

  • (String)

    with the job's interval


40
41
42
# File 'lib/sidekiq-scheduler/job_presenter.rb', line 40

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

#last_timeString

Returns the last execution time for the job

Returns:

  • (String)

    with the job's last time


31
32
33
34
35
# File 'lib/sidekiq-scheduler/job_presenter.rb', line 31

def last_time
  execution_time = SidekiqScheduler::RedisManager.get_job_last_time(name)

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

#next_timeString

Returns the next time execution for the job

Returns:

  • (String)

    with the job's next time


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

def next_time
  execution_time = SidekiqScheduler::RedisManager.get_job_next_time(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


47
48
49
# File 'lib/sidekiq-scheduler/job_presenter.rb', line 47

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