You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

50 lines
1.5 KiB

  1. #!/usr/bin/python
  2. import gearman
  3. def check_request_status(job_request):
  4. if job_request.complete:
  5. print "Job %s finished! Result: %s - %s" % (job_request.job.unique, job_request.state, job_request.result)
  6. elif job_request.timed_out:
  7. print "Job %s timed out!" % job_request.unique
  8. elif job_request.state == JOB_UNKNOWN:
  9. print "Job %s connection failed!" % job_request.unique
  10. def main():
  11. client = gearman.GearmanClient(['localhost:4730', 'otherhost:4730'])
  12. try:
  13. completed_job_request = client.submit_job("ToUpper", "arbitrary binary data")
  14. check_request_status(completed_job_request)
  15. except Exception as e:
  16. print type(e)
  17. try:
  18. completed_job_request = client.submit_job("ToUpperTimeOut5", "arbitrary binary data")
  19. check_request_status(completed_job_request)
  20. except Exception as e:
  21. print type(e)
  22. try:
  23. completed_job_request = client.submit_job("ToUpperTimeOut20", "arbitrary binary data")
  24. check_request_status(completed_job_request)
  25. except Exception as e:
  26. print type(e)
  27. try:
  28. completed_job_request = client.submit_job("SysInfo", "")
  29. check_request_status(completed_job_request)
  30. except Exception as e:
  31. print type(e)
  32. try:
  33. completed_job_request = client.submit_job("MemInfo", "")
  34. check_request_status(completed_job_request)
  35. except Exception as e:
  36. print type(e)
  37. if __name__ == '__main__':
  38. main()