lib/daemon_runner/client.rb in daemon_runner-0.4.0 vs lib/daemon_runner/client.rb in daemon_runner-0.4.1
- old
+ new
@@ -17,24 +17,24 @@
# @param [RuntimeError] error the body of the error
def scheduler.on_error(job, error)
error_sleep_time = job[:error_sleep_time]
on_error_release_lock = job[:on_error_release_lock]
logger = job[:logger]
- task_id = job[:task_id]
+ logger_name = job[:logger_name]
mutex = @mutexes[task_id]
- logger.error "#{task_id}: #{error}"
- logger.debug "#{task_id}: #{error.backtrace.join("\n")}"
- logger.debug "#{task_id}: Suspending #{task_id} for #{error_sleep_time} seconds"
+ logger.error "#{logger_name}: #{error}"
+ logger.debug "#{logger_name}: #{error.backtrace.join("\n")}"
+ logger.debug "#{logger_name}: Suspending #{logger_name} for #{error_sleep_time} seconds"
# Unlock the job mutex if the job owns it and on_error_release_lock is true
mutex.unlock if on_error_release_lock && mutex.owned?
sleep error_sleep_time
- logger.debug "#{task_id}: Resuming #{task_id}"
+ logger.debug "#{logger_name}: Resuming #{logger_name}"
end
end
# Hook to allow initial setup tasks before running tasks.
# @abstract Override {#wait} to pause before starting.
@@ -146,10 +146,12 @@
out[:task_id] = out[:instance].send(:task_id).to_s
else
out[:task_id] = "#{out[:class_name]}.#{out[:method]}"
end
+ out[:logger_name] = "#{out[:class_name]}.#{out[:method]}"
+
raise ArgumentError, 'Invalid task id' if out[:task_id].nil? || out[:task_id].empty?
out[:args] = task[2..-1].flatten
out
end
@@ -186,34 +188,36 @@
schedule = parse_schedule(instance)
class_name = parsed_task[:class_name]
method = parsed_task[:method]
args = parsed_task[:args]
task_id = parsed_task[:task_id]
+ logger_name = parsed_task[:logger_name]
# Schedule the task
- schedule_log_line = "#{task_id}: Scheduling job #{class_name}.#{method} as `:#{schedule[:type]}` type"
+ schedule_log_line = "#{logger_name}: Scheduling job #{class_name}.#{method} as `:#{schedule[:type]}` type"
schedule_log_line += " with schedule: #{schedule[:schedule]}"
logger.debug schedule_log_line
opts = { :overlap => false, :job => true, :mutex => task_id }
opts.merge!(schedule[:extra_opts]) if schedule.key?(:extra_opts)
scheduler.send(schedule[:type], schedule[:schedule], opts) do |job|
- log_line = "#{task_id}: Running #{class_name}.#{method}"
+ log_line = "#{logger_name}: Running #{class_name}.#{method}"
log_line += "(#{args})" unless args.empty?
logger.debug log_line
job[:error_sleep_time] = error_sleep_time
job[:on_error_release_lock] = on_error_release_lock
job[:logger] = logger
job[:task_id] = task_id
+ job[:logger_name] = logger_name
out = if args.empty?
instance.send(method.to_sym)
else
instance.send(method.to_sym, args)
end
- logger.debug "#{task_id}: Got: #{out}"
+ logger.debug "#{logger_name}: Got: #{out}"
end
end
# @return [Rufus::Scheduler] A scheduler instance
def scheduler