Skip to content
Browse files

Simple worker for string reversing

  • Loading branch information...
1 parent f3a6375 commit c6c8bd565d288fba23fb840834ffa4a0c86bb5f4 @kachayev committed Jul 30, 2011
Showing with 27 additions and 0 deletions.
  1. +25 −0 tests/env_stub/workers/reverse.py
  2. +2 −0 tests/settings.py
View
25 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()
+
View
2 tests/settings.py
@@ -28,3 +28,5 @@
# (for more information, look for SleepingGearmanWorker object implementation)
STUB_WORKERS_FREQUENCY = 1.0
+STUB_WORKERS_ID_FORMAT = 'Stub.worker.daemon.%(task)s'
+

0 comments on commit c6c8bd5

Please sign in to comment.
Something went wrong with that request. Please try again.