ProcessHandler helps to spawn and manage services. There are multiple types of processes. Every process knows how to handle SIGINT
and SIGTERM
signals.
This process is used for services that need one or more threads and use the request-response model Freddy.
Example of using pivot process:
service = MyService.new
freddy = Freddy.new
statsd = Statsd.new
logger = Logasm.build('my-app', {stdout: {level: :debug}})
process = Salemove::ProcessHandler::PivotProcess.new(
freddy: freddy,
logger: logger,
statsd: statsd
)
process.spawn(service)
If you want to use pivot process, then the given service must implement call
method that takes input
as an argument.
Example of a service:
class Echo
def call(input)
result = # do something with input
{success: true, output: result} # return result
end
end
end
This process allows a service to run recurringly either at times specified by a cron expression or at a fixed time interval: "1" for seconds, "2h" for hours and "2d" for days.
Example of using cron process with cron expressions:
service = MyService.new
# every five minutes between 7:00 and 7:55 on Mon to Fri
process = Salemove::ProcessHandler::CronProcess.new('0/5 7 * * 1-5')
process.spawn(service)
Example of using cron process with interval expressions:
service = MyService.new
# every second hour
process = Salemove::ProcessHandler::CronProcess.new('2h')
process.spawn(service)
If you want to use a cron process, then you only must implement call
method that does not take any arguments.
Example of a service:
class MemWatcher
def call
result = `sysctl -a | grep 'hw.usermem'`
# e.g write this result to a file
end
end