Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add next time execution at recurring jobs view
- Loading branch information
Cristian Dotta
committed
Jul 11, 2016
1 parent
5e0620f
commit 5b7f2bb
Showing
9 changed files
with
195 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require 'sidekiq/web_helpers' | ||
|
||
module SidekiqScheduler | ||
class JobPresenter | ||
attr_reader :name | ||
|
||
include Sidekiq::WebHelpers | ||
|
||
def initialize(name, attributes) | ||
@name = name | ||
@attributes = attributes | ||
end | ||
|
||
# Returns the next time execution for the job | ||
# | ||
# @return [String] with the job's next time | ||
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 | ||
|
||
# Returns the interval for the job | ||
# | ||
# @return [String] with the job's interval | ||
def interval | ||
@attributes.fetch('cron', @attributes['every']) | ||
end | ||
|
||
# Returns the queue of the job | ||
# | ||
# @return [String] with the job's queue | ||
def queue | ||
@attributes.fetch('queue', 'default') | ||
end | ||
|
||
# Delegates the :[] method to the attributes' hash | ||
# | ||
# @return [String] with the value for that key | ||
def [](key) | ||
@attributes[key] | ||
end | ||
|
||
# Builds the presenter instances for the schedule hash | ||
# | ||
# @param schedule_hash [Hash] with the redis schedule | ||
# @return [Array<JobPresenter>] an array with the instances of presenters | ||
def self.build_collection(schedule_hash) | ||
Hash(schedule_hash).map do |name, job_spec| | ||
new(name, job_spec) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters