Skip to content

Instantly share code, notes, and snippets.

@shunwen
Created January 13, 2015 07:50
Show Gist options
  • Save shunwen/60e8bc9f0d8f42ea7d3b to your computer and use it in GitHub Desktop.
Save shunwen/60e8bc9f0d8f42ea7d3b to your computer and use it in GitHub Desktop.
Worker skeleton
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