Package: rotterdam
Rotterdam is an asynchronous job queue system written in Python with a dab
of Lua, designed with simplicty and ease of use in mind with as few
dependencies as possible.It usesRedisas its datastore and is heavily inspired by theUnicornandGunicornmaster/worker process model.InstallationUsageStarting upSending jobsControlling the master processControlling the number of consumersReloading configuration settingsReloading new codeShutting downLicenseInstallationRotterdam is available via pypi, installing for clients is as easy as:pip install rotterdamTo use the server scripts, install the “server” subproject:pip install rotterdam[server]UsageMake sure to have a redis instance version 2.6 or newer at the location
specified in your config file under thearbitersection.  See the
example.cfg file for an example.Starting upTo start the rotterdam server, run therotterdamexecutable and pass in
the location of a config file (an example.cfg is included in this here repo):[ ~ ] $ rotterdam example.cfg
INFO:rotterdam.master:Starting master (52174)
INFO:rotterdam.master:Listening on port 8765
INFO:rotterdam.master:Starting up consumer
INFO:rotterdam.master:Starting up consumerSending jobsAll a client program has to do is instantiate aRotterdamclass with the
proper host and port and callenqueue:from rotterdam import Rotterdam

client = Rotterdam("localhost")  # default port is 8765

client.enqueue("rotterdam.example:some_job", "thingy", "guy", foo="bar")
client.enqueue("rotterdam.example:some_job", "derp", "hork", foo="bazz")The first argument toenqueuecan either be an instance of a function, or a
string with the full namespace of the function to be run.In this example, the job is a simple function that prints out its own
arguments:import time

def some_job(arg1, arg2, foo=None):
    time.sleep(2)
    print "arg1: %s" % arg1
    print "arg2: %s" % arg2
    print "foo: %s" % fooSo once the client program is run the rotterdam process will print out the args
on its end:arg1: derp
arg2: hork
foo: bazz
arg1: thingy
arg2: guy
foo: barNote that since it’s jobs are executed _concurrently_ with consumer processes
they don’t necessarily execute in the same order the client sends them.Controlling the master processRotterdam uses inter-process communcation (IPC) signals for most tasks so that
the master/worker processes can chug along the whole time without needed to
be restarted.  Therotterdamctlprogram is a handy utility for sending
the proper signals to the proper process.  This program also takes the location
of a config file as the first argument.  Make sure to use the same config file
as the rotterdam process you want to control!Controlling the number of consumersTo add a consumer to the existing rotterdam processes, pass theexpandcommand torotterdamctl.:[ ~ ] $ rotterdamctl example.cfg expandThe master processes will log that a new consumer is added:INFO:rotterdam.master:Upping number of consumers to 3
INFO:rotterdam.master:Starting up consumerContracting the number of consumers is a similiar process, but with thecontractcommand:[ ~ ] $ rotterdamctl example.cfg contract

INFO:rotterdam.master:Contracting number of consumers to 2
INFO:rotterdam.master:Consumer exitingReloading configuration settingsThe rotterdam master process has a facility for reloading its config file
on-the-fly so no work is lost. It is invoked with thereloadcommand torotterdamctl.:[ ~ ] $ rotterdamctl example.cfg reloadThe master process will then re-read the config file and signal each worker
process to wrap up whatever it’s doing while at the same time spawning new
worker processes based on the new config.:INFO:rotterdam.master:Reloading config
INFO:rotterdam.master:Starting up consumer
INFO:rotterdam.master:Starting up consumer
INFO:rotterdam.master:Consumer exiting
INFO:rotterdam.master:Consumer exitingReloading new codeNaturally, rotterdam only knows of the jobs available to its python runtime.
What to do when you update the code to have shiny new jobs, but you don’t want
to shut down or pause any work while updating?  For this case there’s therelaunchcommand:[ ~ ] $ rotteramctl example.cfg relaunchThe master process will spawn a new master with the same arguments it was invoked
with and passes along the listening socket’s file descriptor.:INFO:rotterdam.master:Winding down old master
INFO:rotterdam.master:Starting master (52580)
INFO:rotterdam.master:Listening on port 8765
INFO:rotterdam.master:Starting up consumer
INFO:rotterdam.master:Starting up consumer
INFO:rotterdam.master:Consumer exiting
INFO:rotterdam.master:Consumer exiting
[ ~ ] $Once the new master is up and running, the old master process signals its child
worker processes to wrap up what they’re doing and shuts itself down while the
new master processes chugs along and accepts data on the same socket but with
freshly-loaded python code.Shutting downStopping rotterdam is done via thestopcommand:[ ~ ] $ rotterdamctl example.cfg stop

INFO:rotterdam.master:Winding down master
INFO:rotterdam.master:Consumer exiting
INFO:rotterdam.master:Consumer exitingLicense(c) 2013-2015 William GlassRotterdam licensed under the terms of the MIT license.  See theLICENSEfile
for more details.