Skip to content

Commit

Permalink
before and after fork hooks for worker
Browse files Browse the repository at this point in the history
  • Loading branch information
Whit Morriss committed Feb 23, 2011
1 parent dcfb99c commit 7dbd415
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion pyres/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ def work(self, interval=5):
job = self.reserve(interval)

if job:
logger.info('picked up job')
logger.debug('picked up job')
logger.debug('job details: %s' % job)
self.before_fork(job)
self.child = os.fork()
if self.child:
setproctitle("pyres_worker%s: Forked %s at %s" %
Expand All @@ -163,6 +164,7 @@ def work(self, interval=5):
datetime.datetime.now()))
logger.info('Processing %s since %s' %
(job._queue, datetime.datetime.now()))
self.after_fork(job)
self.process(job)
os._exit(0)
self.child = None
Expand All @@ -175,6 +177,20 @@ def work(self, interval=5):
#time.sleep(interval)
self.unregister_worker()

def before_fork(self, job):
"""
hook for making changes immediately before forking to process
a job
"""
pass

def after_fork(self, job):
"""
hook for making changes immediately after forking to process a
job
"""
pass

def before_process(self, job):
return job

Expand Down

0 comments on commit 7dbd415

Please sign in to comment.