Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rnd-soft/main_loop
[MIRROR] Main Loop implementation to control subprocesses and threads
https://github.com/rnd-soft/main_loop
gem loop mainloop ruby ruby-on-rails
Last synced: about 7 hours ago
JSON representation
[MIRROR] Main Loop implementation to control subprocesses and threads
- Host: GitHub
- URL: https://github.com/rnd-soft/main_loop
- Owner: RND-SOFT
- License: mit
- Created: 2019-09-27T12:28:53.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-04-03T15:02:05.000Z (over 1 year ago)
- Last Synced: 2024-11-15T05:29:11.496Z (5 days ago)
- Topics: gem, loop, mainloop, ruby, ruby-on-rails
- Language: Ruby
- Homepage: https://br.rnds.pro/ruby/main_loop
- Size: 21.5 KB
- Stars: 5
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MainLoop
[![Gem Version](https://badge.fury.io/rb/main_loop.svg)](https://rubygems.org/gems/main_loop)
[![Gem](https://img.shields.io/gem/dt/main_loop.svg)](https://rubygems.org/gems/main_loop/versions)
[![YARD](https://badgen.net/badge/YARD/doc/blue)](http://www.rubydoc.info/gems/main_loop)[![Test Coverage](https://api.codeclimate.com/v1/badges/baf9b1dc3dae87f7edfd/test_coverage)](https://codeclimate.com/github/RnD-Soft/main_loop/test_coverage)
[![Maintainability](https://api.codeclimate.com/v1/badges/baf9b1dc3dae87f7edfd/maintainability)](https://codeclimate.com/github/RnD-Soft/main_loop/maintainability)
[![Quality](https://lysander.rnds.pro/api/v1/badges/main_loop_quality.svg)](https://lysander.x.rnds.pro/api/v1/badges/main_loop_quality.html)
[![Outdated](https://lysander.rnds.pro/api/v1/badges/main_loop_outdated.svg)](https://lysander.x.rnds.pro/api/v1/badges/main_loop_outdated.html)
[![Vulnerabilities](https://lysander.rnds.pro/api/v1/badges/main_loop_vulnerable.svg)](https://lysander.x.rnds.pro/api/v1/badges/main_loop_vulnerable.html)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:
```ruby
require 'main_loop'logger = Logger.new(STDOUT)
logger.level = Logger::DEBUGbus = 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
endMainLoop::ProcessHandler.new dispatcher, 'test2', retry_count: 2, logger: logger do
trap 'TERM' do
exit(0)
end
sleep 2
exit! 1
endMainLoop::ThreadHandler.new dispatcher, 'thread2', retry_count: 0, logger: logger do
system('sleep 15;echo ok')
endmainloop.run
```# Installation
It's a gem:
```bash
gem install main_loop
```
There's also the wonders of [the Gemfile](http://bundler.io):
```ruby
gem 'main_loop'
```