Created
January 13, 2015 07:50
-
-
Save shunwen/60e8bc9f0d8f42ea7d3b to your computer and use it in GitHub Desktop.
Worker skeleton
This file contains hidden or 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
class TestWorker | |
def startup | |
# Change process name | |
$PROGRAM_NAME = "HL7 - noop working..." | |
# Create pid file | |
File.open("tmp/pids/workers.pid", "a") {|f| f.puts Process.pid } | |
# Go daemon and disconnect from STDOUT/STDERR | |
Process.daemon(true) | |
# Trap signal to stop process gracefully | |
@stop = false | |
["TERM", "USR1", "HUP", "USR2"].each do |signal| | |
Signal.trap(signal){ @stop = true } | |
end | |
end | |
def work | |
startup | |
until @stop | |
# Do the work | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment