Skip to content

Commit

Permalink
Simplify the implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
tshead committed Mar 20, 2019
1 parent 7607b91 commit 6e8a423
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
6 changes: 4 additions & 2 deletions buildcat/hou.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
import subprocess
import time

import rq

import buildcat
import buildcat.worker

log = logging.getLogger("rq.worker")


def _hython_executable():
return "hython"

Expand Down Expand Up @@ -82,7 +84,7 @@ def render(hipfile, rop, frames):
start = int(frames[0])
end = int(frames[1])

q = buildcat.worker.queue()
q = rq.Queue(connection=rq.get_current_connection())
for frame in range(start, end):
q.enqueue("buildcat.hou.render_frame", hipfile, rop, frame)

Expand Down
15 changes: 14 additions & 1 deletion buildcat/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@

from __future__ import absolute_import, division, print_function

import rq

import buildcat

def log_message(message):
def log(message):
"""Log a message.
Parameters
Expand All @@ -32,6 +34,17 @@ def log_message(message):
"""
buildcat.log.info(message)

def spawn(count):
"""Create additional jobs.
Parameters
----------
count: int, required
Number of new jobs to create.
"""
for index in range(count):
rq.Queue(connection=rq.get_current_connection()).enqueue("buildcat.test.log", "Job-{}".format(index))

def raise_exception(e):
"""Raise an exception.
Expand Down
18 changes: 0 additions & 18 deletions buildcat/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,4 @@ class Worker(worker_base):
"""
death_penalty_class = death_penalty_class

current_connection = None

def __init__(self, *args, **kwargs):
super(Worker, self).__init__(*args, **kwargs)
Worker.current_connection = self.connection

def queue():
"""Creates a queue connected to the service that initiated the current job.
Useful when a job handler needs to spawn additional jobs.
Returns
-------
queue: :class:`rq.Queue`
New queue pointing to the service where the current job originated.
"""
if Worker.current_connection is None:
raise RuntimeError("Cannot create a queue without a connection. Did you start rq worker with the -w buildcat.worker.Worker option?")
return rq.Queue(connection=Worker.current_connection)

0 comments on commit 6e8a423

Please sign in to comment.