forked from kennethkalmer/daemon-kit
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated cron generator for rufus-scheduler, start of central EventMac…
…hine management code
- Loading branch information
1 parent
777a501
commit 5c2b959
Showing
7 changed files
with
79 additions
and
13 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 |
---|---|---|
@@ -1,7 +1,11 @@ | ||
begin | ||
require 'rufus-scheduler' | ||
require 'rufus/scheduler' | ||
rescue LoadError => e | ||
$stderr.puts "Missing rufus-scheduler gem. Please run 'gem install rufus-scheduler'." | ||
exit 1 | ||
end | ||
|
||
if Rufus::Scheduler::VERSION < "2.0.0" | ||
$stderr.puts "Requires rufus-scheduler-2.0.0 or later" | ||
exit 1 | ||
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
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,43 @@ | ||
module DaemonKit | ||
|
||
# EventMachine forms a critical part of the daemon-kit toolset, and | ||
# especially of daemon process developers. | ||
# | ||
# This class abstracts away the difficulties of managing multiple | ||
# libraries that all utilize the event reactor. | ||
class EM | ||
|
||
class << self | ||
|
||
# Start a reactor, just like classical EM.run. If the block is | ||
# provided, the method will block and call the provided block | ||
# argument inside the running reactor. If the block argument is | ||
# not provided the reactor will be started in a separate thread | ||
# and the program will continue to run after the method. All the | ||
# signal traps are configured to shutdown the reactor when the | ||
# daemon exists. | ||
def run(&block) | ||
if ::EM.reactor_running? | ||
DaemonKit.logger.warn "EventMachine reactor already running" | ||
block.call if block_given? | ||
|
||
else | ||
if block_given? | ||
::EM.run { block.call } | ||
else | ||
Thread.main[:_dk_reactor] = Thread.new { EM.run {} } | ||
DaemonKit.trap( 'INT' ) { DaemonKit::EM.stop } | ||
DaemonKit.trap( 'TERM' ) { DaemonKit::EM.stop } | ||
end | ||
end | ||
end | ||
|
||
# Stop the reactor | ||
def stop | ||
::EM.stop_event_loop if ::EM.reactor_running? | ||
Thread.main[:_dk_reactor].join | ||
end | ||
end | ||
|
||
end | ||
end |