Project

always

0.0
No release in over a year
You may need this framework if you have a routine task that must be performed every once in a while, but may raise exceptions which you don't want to cause a termination of the entire routine cycle.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

 Project Readme

Runs a Background Loop Forever

DevOps By Rultor.com We recommend RubyMine

rake PDD status Gem Version Test Coverage Yard Docs Hits-of-Code License

This simple Ruby gem helps you run a loop forever, in a background thread.

require 'always'
# Prepare, with five threads and a block:
a = Always.new(5) do
  puts "I'm alive"
end
# Start them all together spinning forever with 30-seconds delay between cycles:
a.start!(30)
# Stop them all together:
a.stop!

You may be interested to get the backtraces of the exceptions that happened most recently:

# Keep the last 10 error backtraces in memory:
a = Always.new(5, max_backtraces: 10)
# Set an error handler:
a.on_error do |exception, thread_id|
  puts "Error in thread #{thread_id}: #{exception.message}"
end
# Start them:
a.start!
# Retrieve the backtraces:
p a.backtraces

That's it.

How to contribute

Read these guidelines. Make sure your build is green before you contribute your pull request. You will need to have Ruby 3.0+ and Bundler installed. Then:

bundle update
bundle exec rake

If it's clean and you don't see any error messages, submit your pull request.