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

forked

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

forked

  • 0.1.5
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Forked

License MIT Gem Version Gem Downloads Test Suite

Forked manages long running worker processes.

Processes that crash are restarted, whereas processes that exit successfully aren't. Errors that occur within forked processes are retried according to the configured retry strategy.

Once wait_for_shutdown is called, the current process watches for shutdown signals or crashed processes. On shutdown, each worker is sent a TERM signal, indicating that it should finish any in progress work and shutdown. After a set timeout period workers are sent a KILL signal.

Usage

require 'forked'

process_manager = Forked::ProcessManager.new(logger: Logger.new(STDOUT), process_timeout: 5)

# Default retry_strategy = Forked::RetryStrategies::Always
# Calling `ready_to_stop` within the loop ensures a shutdown is triggered if a TERM/INT signal is received
process_manager.fork('monitor', on_error: ->(e, tries) { puts e.inspect }) do |ready_to_stop|
  loop do
    ready_to_stop.call
    # do something
  end
end

# Using the ExponentialBackoff retry_strategy
# If there is an error, process_manager backs off for a time then restarts the loop
# The back off time increases as the number of errors increase
process_manager.fork('processor_1', retry_strategy: Forked::RetryStrategies::ExponentialBackoff) do |ready_to_stop|
  loop do
    ready_to_stop.call
    # do something
  end
end

# Using the ExponentialBackoffWithLimit retry_strategy
# Follows the ExponentialBackoff retry strategy, but if the error keeps occurring
#   until a given limit (default: 8), the error bubbles up and the loop is not restarted
process_manager.fork('processor_1', retry_strategy: Forked::RetryStrategies::ExponentialBackoffWithLimit, retry_backoff_limit: 10) do |ready_to_stop|
  loop do
    ready_to_stop.call
    # do something
  end
end

# blocks the current process, restarts any crashed processes and waits for shutdown signals (TERM/INT).
process_manager.wait_for_shutdown

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/envato/forked.

FAQs

Package last updated on 02 Aug 2024

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