Project

attention

0.0
No commit activity in last 3 years
No release in over 3 years
Redis-based server awareness for distributed applications
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.13
~> 0.10
~> 10.0
~> 3.4
~> 1.2
>= 0

Runtime

 Project Readme

Attention

Build Status Test Coverage Code Climate Gem Version

Redis-based server awareness for distributed applications

Installation

Add this line to your application's Gemfile:

gem 'attention'

And then execute:

$ bundle

Or install it yourself as:

$ gem install attention

Usage

Activate the instance:

# Autodiscover the ip and exclude the port
Attention.activate

# Or specify them explicitly
Attention.activate ip: '1.2.3.4', port: 9000

The current instance is accessible at:

Attention.instance

Deactivate the instance:

Attention.deactivate

Subscribe to instance availability changes:

Attention.on_change do |change, instances|
  # This block is asynchronously called on each change
end

Or get the list of available instances:

Attention.instances

Configuration

Options can be set on Attention.options

Attention.options = {
  namespace: 'attention',                # Redis key namespace
  ttl: 60,                               # Instance heartbeat TTL in seconds
  redis_url: 'redis://localhost:6379/0', # Redis connection string
  pool_size: 5,                          # Size of the publishing Redis connection pool
  timeout: 5                             # Redis connection timeout
}

Notes

The top-level API provides a simple way to keep track of instance availability. More complex schemes of communication could be implemented by using the Subscriber and Publisher classes directly.

Instances attempt to deactivate themselves when the program terminates(at_exit). If the instance crashes in a dramatic fashion (or a kill -9), the instance will continue to be listed as available until the TTL (Attention.options[:ttl]) expires.

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/parrish/attention. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.