Class: SidekiqScheduler::JobPresenter
- Inherits:
-
Object
- Object
- SidekiqScheduler::JobPresenter
- Includes:
- Sidekiq::WebHelpers
- Defined in:
- lib/sidekiq-scheduler/job_presenter.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.build_collection(schedule_hash) ⇒ Array<JobPresenter>
Builds the presenter instances for the schedule hash.
Instance Method Summary collapse
-
#[](key) ⇒ String
Delegates the :[] method to the attributes’ hash.
- #enabled? ⇒ Boolean
-
#initialize(name, attributes) ⇒ JobPresenter
constructor
A new instance of JobPresenter.
-
#interval ⇒ String
Returns the interval for the job.
-
#last_time ⇒ String
Returns the last execution time for the job.
-
#next_time ⇒ String
Returns the next time execution for the job.
-
#queue ⇒ String
Returns the queue of the job.
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
#name ⇒ Object (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
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
53 54 55 |
# File 'lib/sidekiq-scheduler/job_presenter.rb', line 53 def [](key) @attributes[key] end |
#enabled? ⇒ Boolean
57 58 59 |
# File 'lib/sidekiq-scheduler/job_presenter.rb', line 57 def enabled? Sidekiq::Scheduler.job_enabled?(@name) end |
#interval ⇒ String
Returns the interval for the job
39 40 41 |
# File 'lib/sidekiq-scheduler/job_presenter.rb', line 39 def interval @attributes['cron'] || @attributes['interval'] || @attributes['every'] end |
#last_time ⇒ String
Returns the last execution time for the job
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_time ⇒ String
Returns the next time execution for the job
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 |
#queue ⇒ String
Returns the queue of the job
46 47 48 |
# File 'lib/sidekiq-scheduler/job_presenter.rb', line 46 def queue @attributes.fetch('queue', 'default') end |