sirupsen/localjob is an open-source project on GitHub with 144 stars, written primarily in Ruby. Simple, self-contained background queue built on top of SysV message queues.
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
Localjob is a simple, self-contained background queue built on top of System V
message queues (SysV Message Queue => SysV MQ for short). The SysV
message queue API is implemented by the kernel. It's very stable and performant.
This means workers and the app pushing to the queue must reside on the same
machine. It's the sqlite of background queues. Here's a post about how it
works. You can run Localjob either as a seperate process, or as a thread
in your app.
Localjob is for early-development situations where you don't need a
full-featured background queue, but just want to get started with something
simple that does not rely on any external services. The advantage of the SysV
queues is that your Rails app or worker can restart at any time, without loosing
any events.
Localjob works on Ruby >= 2.0.0 on Linux and OS X.
Add it to your Gemfile:
gem 'localjob'
Usage
Localjobs have the following format:
class EmailJob
def initialize(user_id, email)
@user, @email = User.find(user_id), email
end
def perform
@email.deliver_to(@user)
end
end
To queue a job, create an instance of it and push it to the queue:
A job is serialized with YAML and pushed onto a persistent SysV Message Queue.
This means a worker does not have to listen on the queue to push things to it.
Pops off the message queue are atomic, so only one will receive the queue. This
means you can run multiple workers on the same machine if you wish. The workers
will deserialize the message to create an instance of your object, and call
#perform on the object.
Rails initializer
For easy access to your queues in Rails, you can add an initializer to set up a
constant referencing each of your queues. This allows easy access anywhere in
your app. In config/initializers/localjob.rb:
BackgroundQueue = Localjob.new
Then in your app you can simply reference the constant to push to the queue:
There are two ways to spawn workers, either a thread inside the process emitting
events, or as a separate process managed with the localjob command-line
utility.
Thread
Spawn the worker thread in an initializer where you are initializing Localjob as
well:
Spawning workers can be done with localjob. Run localjob work to spawn a
single worker. It takes a few arguments. The most important being --require
which takes a path the worker will require before processing jobs. For Rails,
you can run localjob work without any arguments. localjob(2) has a few other
commands such as list to list all queues and size to list the size of all
queues. localjob help to list all commands.
Gracefully shut down workers by sending SIGQUIT to them. This will make sure
the worker completes its current job before shutting down. Jobs can be sent to
the queue meanwhile, and the worker will process them once it starts again.
Testing
Create your instance of the queue as normal in your setup:
def setup
@queue = Localjob.new
@worker = Localjob::Worker.new(@queue)
end
In your teardown you'll want to destroy your queue:
def teardown
@queue.destroy
end
You can get the size of your queue by calling @queue.size. You pop off the
queue with @queue.shift. Other than that, just use the normal API. You can
also read the tests for Localjob to get an idea of how to test. Sample test:
If you wish to have multiple queues you can have multiple Localjob objects
referencing different queues. A worker can only work off a single queue at a
time, so you will have to spawn multiple thread or process workers. Example:
The most recent commit recorded on sirupsen/localjob was 10.3 years ago, based on the GitHub push timestamp. The repository has 6 forks — one of the better signals of community interest.
How many stars does sirupsen/localjob have?
sirupsen/localjob has 144 GitHub stars — refresh the page for the live number, or check github.com/sirupsen/localjob. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
Is sirupsen/localjob open source?
Yes — sirupsen/localjob ships under the MIT license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/sirupsen/localjob.
What is sirupsen/localjob?
sirupsen/localjob (sirupsen/localjob) is a Ruby project on GitHub. From the project's own README: Simple, self-contained background queue built on top of SysV message queues.
Where do I read more about sirupsen/localjob?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/sirupsen/localjob is the definitive source.
Read full README in the tab above.
Want a second opinion on localjob?
Ask an AI that can read this page — one click and you get its take on localjob.