Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use Logger severities instead of verbose/mute attributes

  • Loading branch information...
commit 1c6af8992b67f32d68ac80522806ccb549519556 1 parent a411b1e
@yabawock authored
View
1  lib/qu-scheduler/tasks.rb
@@ -16,7 +16,6 @@
File.open(ENV['PIDFILE'], 'w') { |f| f << Process.pid.to_s } if ENV['PIDFILE']
Qu::Scheduler.dynamic = true if ENV['DYNAMIC_SCHEDULE']
- Qu::Scheduler.verbose = true if ENV['VERBOSE']
Qu::Scheduler.run
end
View
2  lib/qu/extensions/scheduler/redis.rb
@@ -80,7 +80,7 @@ def load_schedule!
# Need to load the schedule from redis for the first time if dynamic
Qu.reload_schedule! if Qu::Scheduler.dynamic
- Qu::Scheduler.log! "Schedule empty! Set Qu.schedule" if Qu.schedule.empty?
+ Qu.logger.warning("Schedule empty! Set Qu.schedule") if Qu.schedule.empty?
@@scheduled_jobs = {}
View
36 lib/qu/scheduler.rb
@@ -9,12 +9,6 @@ class Scheduler
@@scheduled_jobs = {}
class << self
- # If true, logs more stuff...
- attr_accessor :verbose
-
- # If set, produces no output
- attr_accessor :mute
-
# If set, will try to update the schedule in the loop
attr_accessor :dynamic
@@ -78,10 +72,10 @@ def register_signal_handlers
def print_schedule
if rufus_scheduler
- Qu::Scheduler.log! "Scheduling Info\tLast Run"
+ Qu.logger.info("Scheduling Info\tLast Run")
scheduler_jobs = rufus_scheduler.all_jobs
scheduler_jobs.each do |k, v|
- Qu::Scheduler.log! "#{v.t}\t#{v.last}\t"
+ Qu.logger.info("#{v.t}\t#{v.last}")
end
end
end
@@ -99,13 +93,13 @@ def load_schedule_job(name, config)
# job should be scheduled regardless of what ENV['RAILS_ENV'] is set
# to.
if config['rails_env'].nil? || rails_env_matches?(config)
- Qu::Scheduler.log! "Scheduling #{name} "
+ Qu.logger.info("Scheduling #{name}")
interval_defined = false
interval_types = %w{cron every}
interval_types.each do |interval_type|
if !config[interval_type].nil? && config[interval_type].length > 0
@@scheduled_jobs[name] = rufus_scheduler.send(interval_type, config[interval_type]) do
- Qu::Scheduler.log! "queueing #{config['class']} (#{name})"
+ Qu.logger.info("queueing #{config['class']} (#{name})")
handle_errors { enqueue_from_config(config) }
end
interval_defined = true
@@ -113,7 +107,7 @@ def load_schedule_job(name, config)
end
end
unless interval_defined
- Qu::Scheduler.log! "no #{interval_types.join(' / ')} found for #{config['class']} (#{name}) - skipping"
+ Qu.logger.warn("no #{interval_types.join(' / ')} found for #{config['class']} (#{name}) - skipping")
end
end
end
@@ -143,7 +137,7 @@ def enqueue_delayed_items_for_timestamp(timestamp)
begin
handle_shutdown do
if item = Qu.backend.next_item_for_timestamp(timestamp)
- Qu::Scheduler.log "queuing #{item['klass']} [delayed]"
+ Qu.logger.debug("queuing #{item['klass']} [delayed]")
handle_errors { enqueue_from_config(item) }
end
end
@@ -161,7 +155,7 @@ def handle_errors
begin
yield
rescue Exception => e
- Qu::Scheduler.log! "#{e.class.name}: #{e.message}"
+ Qu.logger.fatal("#{e.class.name}: #{e.message}")
end
end
@@ -204,7 +198,7 @@ def reload_schedule!
def unschedule_job(name)
if scheduled_jobs[name]
- Qu::Scheduler.log "Removing schedule #{name}"
+ Qu.logger.debug("Removing schedule #{name}")
scheduled_jobs[name].unschedule
@@scheduled_jobs.delete(name)
end
@@ -224,22 +218,10 @@ def shutdown
exit if @sleeping
end
- def log!(msg)
- Qu.logger.info "#{Time.now.strftime("%Y-%m-%d %H:%M:%S")} #{msg}" unless mute
- end
-
- def log(msg)
- # add "verbose" logic later
- Qu::Scheduler.log!(msg) if verbose
- end
-
def set_process_title(string)
- Qu::Scheduler.log! string
+ Qu.logger.info(string)
$0 = "qu-scheduler-#{Qu::Scheduler::VERSION}: #{string}"
end
-
end
-
end
-
end
View
1  test/delayed_queue_test.rb
@@ -3,7 +3,6 @@
context "DelayedQueue" do
setup do
- Qu::Scheduler.mute = true
Qu.backend.redis.flushall
end
View
1  test/scheduler_args_test.rb
@@ -11,7 +11,6 @@ def run_job_for_queue(*queues)
setup do
Qu::Scheduler.clear_schedule!
Qu::Scheduler.dynamic = false
- Qu::Scheduler.mute = true
end
test "enqueue_from_config with_every_syntax" do
View
1  test/scheduler_hooks_test.rb
@@ -28,7 +28,6 @@ def clean
Qu::Scheduler.dynamic = false
Qu.backend.redis.del(:schedules)
Qu.backend.redis.del(:schedules_changed)
- Qu::Scheduler.mute = true
Qu::Scheduler.clear_schedule!
Qu::Scheduler.send(:class_variable_set, :@@scheduled_jobs, {})
end
View
1  test/scheduler_test.rb
@@ -6,7 +6,6 @@
Qu::Scheduler.dynamic = false
Qu.backend.redis.del(:schedules)
Qu.backend.redis.del(:schedules_changed)
- Qu::Scheduler.mute = true
Qu::Scheduler.clear_schedule!
Qu::Scheduler.send(:class_variable_set, :@@scheduled_jobs, {})
end
View
3  test/test_helper.rb
@@ -51,6 +51,9 @@
c.connection = Redis::Namespace.new('qu:scheduler', :redis => Redis.new(:host => 'localhost', :port => '9736'))
end
+# Set logging threshold to unknown to suppress log output during tests
+Qu.logger.level = Logger::UNKNOWN
+
##
# test/spec/mini 3
# http://gist.github.com/25455
Please sign in to comment.
Something went wrong with that request. Please try again.