Skip to content

nicoolas25/tennis

Repository files navigation

This is a celluloid based background jobs library heavily inspired by Sidekiq. The difference is that it allows you to change the backend, Redis, to other ones like RabitMQ. You can start with something à la sucker_punch: background jobs threaded within the application process and switch to separated processes later using another backend.

This work has been partly made possible because of R&D time that is given to me by my employer: Tigerlily.

Configuration

Install the gem in your Gemfile:

gem "tennis-jobs"
gem "tennis-jobs-redis" # or "tennis-jobs-rmq" or another backend

Configure Tennis in your config/application.rb (or any other file):

Tennis.configure do |config|
  config.logger = Logger.new(STDOUT)
  config.backend Tennis::Backend::Redis.new(logger: config.logger, url: redis_url)
end

Start tennis from the command line:

bundle exec tennis --concurrency 4 --require ./config/application.rb --jobs "MyJob,MyOtherJob"

# There is also a shorter equivalent:
# bundle exex tennis -c 4 -r ./config/application.rb -j "MyJob,MyOtherJob"

Usage

MINUTES = 60

class MyJob
  include Tennis::Job

  def my_method(*args)
    puts "=> #{args}.sum = args.inject(&:+)"
  end
end

my_job_instance = MyJob.new
my_job_instance.async.my_method(1, 2, 3)

# Will print in your `tennis` process:
# => [1, 2, 3].sum = 6

# Comming soon...
my_job_instance.async_in(2 * MINUTES).my_method(4, 5, 6)

# Will print, in approximatively two minutes, in your `tennis` process:
# => [4, 5, 6].sum = 15

The my_method's arguments can be quite complex depending on your backend support. The same goes for the MyJob's instance.

With the Tennis::Backend::Memory backend, you can use anything and it will be kept as it is.

Backends

Testing

This section is waiting to beeing written.

About

A backend agnostic, actor based, background jobs library.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages