Module: ResqueWeb::Plugins::ResqueScheduler::SchedulesHelper
- Defined in:
- app/helpers/resque_web/plugins/resque_scheduler/schedules_helper.rb
Overview
Helper methods for the schedule UI
Instance Method Summary collapse
-
#queue_from_class_name(class_name) ⇒ String
Returns the name of the queue that a given class uses.
-
#rails_env(name) ⇒ String
Returns the Rails env for the Resque schedule.
-
#schedule_class(config) ⇒ String
Retrieves the class name of the job from the job config and returns it.
-
#schedule_interval(config) ⇒ String
Outputs a human readable string for the UI, showing when the job is scheduled.
-
#schedule_interval_every(every) ⇒ String
Outputs a human readable string showing the schedule for a job when it it configured for every X interval.
-
#scheduled_in_this_env?(name) ⇒ true, false
Tells us whether this job is scheduled for e.g.
Instance Method Details
#queue_from_class_name(class_name) ⇒ String
Returns the name of the queue that a given class uses.
73 74 75 76 77 |
# File 'app/helpers/resque_web/plugins/resque_scheduler/schedules_helper.rb', line 73 def queue_from_class_name(class_name) Resque.queue_from_class( Resque::Scheduler::Util.constantize(class_name) ) end |
#rails_env(name) ⇒ String
Returns the Rails env for the Resque schedule
20 21 22 |
# File 'app/helpers/resque_web/plugins/resque_scheduler/schedules_helper.rb', line 20 def rails_env(name) Resque.schedule[name]['rails_env'] end |
#schedule_class(config) ⇒ String
Retrieves the class name of the job from the job config and returns it
61 62 63 64 65 66 67 |
# File 'app/helpers/resque_web/plugins/resque_scheduler/schedules_helper.rb', line 61 def schedule_class(config) if config['class'].nil? && !config['custom_job_class'].nil? config['custom_job_class'] else config['class'] end end |
#schedule_interval(config) ⇒ String
Outputs a human readable string for the UI, showing when the job is scheduled.
47 48 49 50 51 52 53 54 55 |
# File 'app/helpers/resque_web/plugins/resque_scheduler/schedules_helper.rb', line 47 def schedule_interval(config) if config['every'] schedule_interval_every(config['every']) elsif config['cron'] 'cron: ' + config['cron'].to_s else 'Not currently scheduled' end end |
#schedule_interval_every(every) ⇒ String
Outputs a human readable string showing the schedule for a job when it it configured for every X interval.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/helpers/resque_web/plugins/resque_scheduler/schedules_helper.rb', line 29 def schedule_interval_every(every) every = [*every] s = 'every: ' << every.first return s unless every.length > 1 s << ' (' = every.last.map do |key, value| "#{key.to_s.gsub(/_/, ' ')} #{value}" end s << .join(', ') << ')' end |
#scheduled_in_this_env?(name) ⇒ true, false
Tells us whether this job is scheduled for e.g. the production env. Jobs for other environments may be in Redis but should be ignored.
11 12 13 14 |
# File 'app/helpers/resque_web/plugins/resque_scheduler/schedules_helper.rb', line 11 def scheduled_in_this_env?(name) return true if Resque.schedule[name]['rails_env'].nil? rails_env(name).split(/[\s,]+/).include?(Resque::Scheduler.env) end |