-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbean.py
More file actions
33 lines (25 loc) · 1.14 KB
/
bean.py
File metadata and controls
33 lines (25 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Bean is a tiny little worker friend (rqworker) that pulls tasks off the RQ redis work
# queue and crunches a job -- it's able to preload the opencv library ahead of time so
# we save some cycles and memory. Isn't it adorable?
# Taken from http://python-rq.org/docs/workers/
#
# Daniel Guilak <daniel.guilak@gmail.com> and Josef Lange <josef.d.lange@gmail.com>
# http://github.com/expresso-math/
import sys
from rq import Queue, Connection, Worker
from roaster_settings import settings
# Preloading libraries
# It seems as though we'll have to have a python file with function definitions on both
# barista and roaster, otherwise bean will have no idea what to run -- you can't pass
# a function by name, apparently. Can still preload, though!
# REPLY: I think if you pass the function name with module name as well, it can figure out what it's looking for.
import roaster
REDIS_HOST = settings['rq_hostname']
REDIS_PORT = settings['rq_port']
REDIS_DB = settings['rq_db']
# Provide queue names to listen to as arguments to this script,
# similar to rqworker
with Connection():
qs = map(Queue, sys.argv[1:]) or [Queue()]
w = Worker(qs)
w.work()