Project

main_loop

0.0
No release in over 3 years
Low commit activity in last 3 years
Main Loop implementation to control subprocesses and threads
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

MainLoop

Gem Version Gem YARD

Test Coverage Maintainability Quality Outdated Vulnerabilities

MainLoop is a simple main application implementation to control subprocesses(children) and threads.

Features:

  • reaping children
  • handling SIGTERM SIGINT to shutdown children(and threads) gracefully
  • restarting children
  • termination the children

Usage

Example usage:

require 'main_loop'

logger = Logger.new(STDOUT)
logger.level = Logger::DEBUG

bus = MainLoop::Bus.new

dispatcher = MainLoop::Dispatcher.new(bus, logger: logger)
mainloop = MainLoop::Loop.new(bus, dispatcher, logger: logger)

MainLoop::ProcessHandler.new dispatcher, 'test1', retry_count: 3, logger: logger do
  sleep 2
  exit! 0
end

MainLoop::ProcessHandler.new dispatcher, 'test2', retry_count: 2, logger: logger do
  trap 'TERM' do
    exit(0)
  end
  sleep 2
  exit! 1
end

MainLoop::ThreadHandler.new dispatcher, 'thread2', retry_count: 0, logger: logger do
  system('sleep 15;echo ok')
end

mainloop.run

Installation

It's a gem:

  gem install main_loop

There's also the wonders of the Gemfile:

  gem 'main_loop'