Module: ResqueAdmin::Scheduler::Server::HelperMethods
- Defined in:
- lib/resque/scheduler/server.rb,
lib/resque_admin/scheduler/server.rb
Instance Method Summary collapse
- #find_job(worker) ⇒ Object
- #format_time(t) ⇒ Object
- #queue_from_class_name(class_name) ⇒ Object
- #rails_env(name) ⇒ Object
- #schedule_class(config) ⇒ Object
- #schedule_interval(config) ⇒ Object
- #schedule_interval_every(every) ⇒ Object
- #scheduled_in_this_env?(name) ⇒ Boolean
- #scheduler_template(name) ⇒ Object
- #scheduler_view(filename, options = {}, locals = {}) ⇒ Object
- #show_job_arguments(args) ⇒ Object
Instance Method Details
#find_job(worker) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/resque/scheduler/server.rb', line 154 def find_job(worker) worker = worker.downcase results = working_jobs_for_worker(worker) dels = delayed_jobs_for_worker(worker) results += dels.select do |j| j['class'].downcase.include?(worker) && j.merge!('where_at' => 'delayed') end ResqueAdmin.queues.each do |queue| queued = ResqueAdmin.peek(queue, 0, ResqueAdmin.size(queue)) queued = [queued] unless queued.is_a?(Array) results += queued.select do |j| j['class'].downcase.include?(worker) && j.merge!('queue' => queue, 'where_at' => 'queued') end end results end |
#format_time(t) ⇒ Object
140 141 142 |
# File 'lib/resque/scheduler/server.rb', line 140 def format_time(t) t.strftime(::ResqueAdmin::Scheduler::Server::TIMESTAMP_FORMAT) end |
#queue_from_class_name(class_name) ⇒ Object
148 149 150 151 152 |
# File 'lib/resque/scheduler/server.rb', line 148 def queue_from_class_name(class_name) ResqueAdmin.queue_from_class( ResqueAdmin::Scheduler::Util.constantize(class_name) ) end |
#rails_env(name) ⇒ Object
218 219 220 |
# File 'lib/resque/scheduler/server.rb', line 218 def rails_env(name) ResqueAdmin.schedule[name]['rails_env'] || ResqueAdmin.schedule[name]['env'] end |
#schedule_class(config) ⇒ Object
199 200 201 202 203 204 205 |
# File 'lib/resque/scheduler/server.rb', line 199 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) ⇒ Object
176 177 178 179 180 181 182 183 184 |
# File 'lib/resque/scheduler/server.rb', line 176 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) ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/resque/scheduler/server.rb', line 186 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.tr('_', ' ')} #{value}" end s << .join(', ') << ')' end |
#scheduled_in_this_env?(name) ⇒ Boolean
213 214 215 216 |
# File 'lib/resque/scheduler/server.rb', line 213 def scheduled_in_this_env?(name) return true if rails_env(name).nil? rails_env(name).split(/[\s,]+/).include?(ResqueAdmin::Scheduler.env) end |
#scheduler_template(name) ⇒ Object
207 208 209 210 211 |
# File 'lib/resque/scheduler/server.rb', line 207 def scheduler_template(name) File.read( File.("../server/views/#{name}.erb", __FILE__) ) end |
#scheduler_view(filename, options = {}, locals = {}) ⇒ Object
222 223 224 225 |
# File 'lib/resque/scheduler/server.rb', line 222 def scheduler_view(filename, = {}, locals = {}) source = File.read(File.join(VIEW_PATH, "#{filename}.erb")) erb source, , locals end |
#show_job_arguments(args) ⇒ Object
144 145 146 |
# File 'lib/resque/scheduler/server.rb', line 144 def show_job_arguments(args) Array(args).map(&:inspect).join("\n") end |