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.
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
#name ⇒ Object (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
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
54 55 56 |
# File 'lib/sidekiq-scheduler/job_presenter.rb', line 54 def [](key) @attributes[key] end |
#enabled? ⇒ Boolean
58 59 60 |
# File 'lib/sidekiq-scheduler/job_presenter.rb', line 58 def enabled? SidekiqScheduler::Scheduler.job_enabled?(@name) end |
#interval ⇒ String
Returns the interval for the job
40 41 42 |
# File 'lib/sidekiq-scheduler/job_presenter.rb', line 40 def interval @attributes['cron'] || @attributes['interval'] || @attributes['every'] || @attributes['at'] || @attributes['in'] end |
#last_time ⇒ String
Returns the last execution time for the job
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_time ⇒ String
Returns the next time execution for the job
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 |
#queue ⇒ String
Returns the queue of the job
47 48 49 |
# File 'lib/sidekiq-scheduler/job_presenter.rb', line 47 def queue @attributes.fetch('queue', 'default') end |