Skip to content

Commit

Permalink
Simple worker for string reversing
Browse files Browse the repository at this point in the history
  • Loading branch information
kachayev committed Jul 30, 2011
1 parent f3a6375 commit c6c8bd5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/env_stub/workers/reverse.py
@@ -0,0 +1,25 @@
import tests.settings as settings

from sleeping import worker

def task_listener(gearman_worker, gearman_job):
'''
Per each poll from gearman node,
worker will call this function and give context params: worker and job
'''
done = gearman_job.data[::-1]

# Log result of string reversing in order to control worker activity
# TODO: logging!
print 'Done <%s>' % done
return done

# Setting client ID can be useful for analyzing information
# from gearman admin client, which show list of
# currently connected workers by its CLIENT ID
worker.set_client_id(settings.STUB_WORKERS_ID_FORMAT % {'task': 'reverse'})
worker.register_task('reverse', task_listener)

# Run worker in infinitive loop
worker.work()

2 changes: 2 additions & 0 deletions tests/settings.py
Expand Up @@ -28,3 +28,5 @@
# (for more information, look for SleepingGearmanWorker object implementation) # (for more information, look for SleepingGearmanWorker object implementation)
STUB_WORKERS_FREQUENCY = 1.0 STUB_WORKERS_FREQUENCY = 1.0


STUB_WORKERS_ID_FORMAT = 'Stub.worker.daemon.%(task)s'

0 comments on commit c6c8bd5

Please sign in to comment.