Package: django-leek
Django LeekThesimpleandslickway to run async tasks in Django.Django-friendly APIEasy to start and stopBased ondjango-queue.Why?With a healthy mix of vegetables, such asCeleryandCarrotaleady in the midst, what doesdjango-leekbring?The most "lightweight" library so far has "install Redis" as step one. Although, Redis is a fantastic software, sometimes you just want a simple way of offload the webserver and run a task async, such as sending an email.Heredjango-leekcomes to the rescue. Usage and architecture cannot be simpler, and with so few moving parts, it should be very stable, although it's still not battle tested as e.g. Celery.Withdjango-leekyou can get up and running quickly The more complex distributed queues can wait until the website has a lot of traffic, and the scalability is really required.Getting startedInstalldjango-leekwith pip$pipinstalldjango-leekAdddjango_leektoINSTALLED_APPSin yoursettings.pyfile.Create tables needed$manange.pymigrateMake sure the django-leek server is running.$pythonmanage.pyleekGo nutsleek=Leek()@leek.taskdefsend_mail(to):do_what_ever()send_mail.offload(to='foobar@example.com')You can also use the "old" as found indjango-queuepush_task_to_queue(send_mail,to='foobar@example.com')It's easy to unit test code that in production offloads work to the Leek server.def_invoke(a_callable,*args,**kwargs):a_callable(*args, **kwargs)
@patch('django_leek.api.push_task_to_queue', _invoke)
def test_mytest():
send_mail.offload(to='sync@leek.com')  # now runs synchronously, like a normal function
```DevelopmentThere is a test application you can play around with when developing ondjango-leek. Example:./manage.sh test_app runserver- Starts the test app./manage.sh test_app leek- Starts a leek instance for the test app./manage.sh django_leek test- Run test suite.Technical overviewIn a nutshell, a python SocketServer runs in the background, listening on a tcp socket. SocketServer gets the request to run a task from it's socket, puts the task on a Queue. A Worker thread picks tasks from this Queue, and runs the tasks one by one.ComponentsPython SocketServer that listens to a tcp socket.A Worker thread.A python QueueWorkflowThe workflow that runs an async task:WhenSocketServerstarts, it initializes theWorkerthread.SocketServerlistens to requests.WhenSocketServerreceives a request - a callables with args and kwargs -   it puts the request on a pythonQueue.TheWorkerthread picks a task from theQueue.TheWorkerthread runs the task.Can this queue scale to production?Depends on the traffic: SocketServer is simple, but solid, and as the site gets more traffic, it's possible to move the django-queue server to another machine, separate database etc. At some point, probably, it's better to pick Celery. Until then, django-leek is a simple, solid, and no-hustle solution.SettingsTo change the default django-queue settings, add aLEEKdictionary to your project mainsettings.pyfile.This is the dictionary and the defaults:LEEK = {
	'bind': "localhost:8002",
 	'host': "localhost",
 	'port': 8002}bindThe leek server will bind here.hostThe django server will connect to this host when notifying leek of jobs.portThe django server will connect to this port when notifying leek of jobs.PersistenceThe following models are used.QueuedTasksThe model saves every tasks pushed to the queue.The task is pickled as atasks_queue.tasks.Taskobject, which is a simple class with acallable,argsandkwargsattributes, and one method:run()SuccessTasksThe Worker thread saves to this model thetask_idof every task that was carried out successfuly.task_idis the task'sQueuedTasksid.FailedTasksAfter the Worker tries to run a task and it fails by raising an exception, the Worker saves it to this model. The failed taks is saved by thetask_id, with the exception message. Only the exception from the last run is saved.Purge TasksAccording to your project needs, you can purge tasks that the Worker completed successfuly.The SQL to delete these tasks:DELETE queued,success
FROM tasks_queue_queuedtasks queued
INNER JOIN tasks_queue_successtasks success
ON success.task_id = queued.id;In a similar way, delete the failed tasks.
You can run a cron script, or other script, to purge the tasks.Release a new versionCheckout master branchMake sure virtual environment is activated.source venv/bin/activateMake sure version insetup.pyis correct.grep version setup.pyMake sure setuptools, twine, and wheel are installed and up to datepip install "setuptools>=38.6.0" "twine>=1.11.0" "wheel>=0.31.0"Clean out any old dist packages.rm -r dist/Build source and wheel dists.python setup.py sdist bdist_wheelUpload to PyPItwine upload dist/*Profit!AuthorsAviah, Silvia Scalisi and Samuel CarlssonSeecontributorsfor full list.