forked from resque/resque-scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracting some of Resque::Scheduler's functionality into modules
although this is admittedly not an awesome solution. Needs more work.
- Loading branch information
1 parent
8aa1e67
commit 3525f40
Showing
6 changed files
with
151 additions
and
125 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# vim:fileencoding=utf-8 | ||
|
||
module Resque | ||
module Scheduler | ||
module Configuration | ||
# Allows for block-style configuration | ||
def configure | ||
yield self | ||
end | ||
|
||
# Used in `#load_schedule_job` | ||
attr_writer :env | ||
|
||
def env | ||
return @env if @env | ||
@env ||= Rails.env if defined?(Rails) | ||
@env ||= ENV['RAILS_ENV'] | ||
@env | ||
end | ||
|
||
# If true, logs more stuff... | ||
attr_writer :verbose | ||
|
||
def verbose | ||
@verbose ||= !!ENV['VERBOSE'] | ||
end | ||
|
||
# If set, produces no output | ||
attr_writer :mute | ||
|
||
def mute | ||
@mute ||= !!ENV['MUTE'] | ||
end | ||
|
||
# If set, will write messages to the file | ||
attr_writer :logfile | ||
|
||
def logfile | ||
@logfile ||= ENV['LOGFILE'] | ||
end | ||
|
||
# Sets whether to log in 'text' or 'json' | ||
attr_writer :logformat | ||
|
||
def logformat | ||
@logformat ||= ENV['LOGFORMAT'] | ||
end | ||
|
||
# If set, will try to update the schedule in the loop | ||
attr_writer :dynamic | ||
|
||
def dynamic | ||
@dynamic ||= !!ENV['DYNAMIC_SCHEDULE'] | ||
end | ||
|
||
# If set, will append the app name to procline | ||
attr_writer :app_name | ||
|
||
def app_name | ||
@app_name ||= ENV['APP_NAME'] | ||
end | ||
|
||
# Amount of time in seconds to sleep between polls of the delayed | ||
# queue. Defaults to 5 | ||
attr_writer :poll_sleep_amount | ||
|
||
def poll_sleep_amount | ||
@poll_sleep_amount ||= | ||
Float(ENV.fetch('RESQUE_SCHEDULER_INTERVAL', '5')) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# vim:fileencoding=utf-8 | ||
|
||
module Resque | ||
module Scheduler | ||
module SignalHandling | ||
attr_writer :signal_queue | ||
|
||
def signal_queue | ||
@signal_queue ||= [] | ||
end | ||
|
||
# For all signals, set the shutdown flag and wait for current | ||
# poll/enqueing to finish (should be almost instant). In the | ||
# case of sleeping, exit immediately. | ||
def register_signal_handlers | ||
%w(INT TERM USR1 USR2 QUIT).each do |sig| | ||
trap(sig) { signal_queue << sig } | ||
end | ||
end | ||
|
||
def handle_signals | ||
loop do | ||
sig = signal_queue.shift | ||
break unless sig | ||
log! "Got #{sig} signal" | ||
case sig | ||
when 'INT', 'TERM', 'QUIT' then shutdown | ||
when 'USR1' then print_schedule | ||
when 'USR2' then reload_schedule! | ||
end | ||
end | ||
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