Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sigurd

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sigurd

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

sigurd

Small gem to manage executing looping processes and signal handling.

Gem Version

Installation

Add this line to your application's Gemfile:

gem 'sigurd'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sigurd

Versioning

We use a version of semver for this gem. Any change in previous behavior (something works differently or something old no longer works) is denoted with a bump in the minor version (0.4 -> 0.5). Patch versions are for bugfixes or new functionality which does not affect existing code. You should be locking your Gemfile to the minor version:

gem 'sigurd', '0.0.3'

Usage

Sigurd exposes two classes for use with a third class. The ideas is as follows:

  • You have any object which responds to the start and stop methods. This object is called a "Runner". When the stop method is called, the runner should gracefully shut down.
  • You create an Executor class - this manages a thread pool for a list of runners.
  • You create a SignalHandler which is the topmost object. This will handle the signals sent by the system and gracefully forward the requests. You pass the executor into the SignalHandler.
  • Finally, you call start on the SignalHandler to begin the execution.

Sample code:

class TestRunner

def start
  loop do
    break if @signal_to_stop
    # do some logic here
  end
end

  def stop
    @signal_to_stop = true
  end
end

runners = (1..2).map { TestRunner.new }
executor = Sigurd::Executor.new(runners, sleep_seconds: 5, logger: Logger.new(STDOUT))
Sigurd::SignalHandler.new(executor).run!

If you have only a single runner, you can pass it into the SignalHandler directly, without using an Executor:

  Sigurd::SignalHandler.new(runner).run!

By default, if any of your runners fails, Sigurd will use an exponential backoff to wait before restarting it. You can instead use the sleep_seconds setting to always sleep a fixed amount of time before retrying. There is no limit to retries.

Configuration

By default, sigurd will exit the process when a TERM, KILL or QUIT signal is received. You can change this behavior to instead raise the original SignalException by setting

Sigurd.exit_on_signal = true

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/flipp-oss/sigurd .

Linting

Sigurd uses Rubocop to lint the code. Please run Rubocop on your code before submitting a PR.


Sponsored by

FAQs

Package last updated on 20 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc