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



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

def self.build_collection(schedule_hash)
  schedule_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



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

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

#enabled?Boolean

Returns:

  • (Boolean)


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

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

#intervalString

Returns the interval for the job

Returns:

  • (String)

    with the job’s interval



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

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



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

def last_time
  execution_time = Sidekiq.redis { |r| r.hget(Sidekiq::Scheduler.last_times_key, 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



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



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

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