PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/resque-scheduler.php

https://github.com/omeryar/php-resque-scheduler
PHP | 61 lines | 45 code | 10 blank | 6 comment | 12 complexity | 6ff18fb720e1402b860c6410b32e4456 MD5 | raw file
  1. <?php
  2. // Look for an environment variable with
  3. $RESQUE_PHP = getenv('RESQUE_PHP');
  4. if (!empty($RESQUE_PHP)) {
  5. require_once $RESQUE_PHP;
  6. }
  7. // Otherwise, if we have no Resque then assume it is in the include path
  8. else if (!class_exists('Resque')) {
  9. require_once 'Resque/Resque.php';
  10. }
  11. // Load resque-scheduler
  12. require_once dirname(__FILE__) . '/lib/ResqueScheduler.php';
  13. require_once dirname(__FILE__) . '/lib/ResqueScheduler/Worker.php';
  14. $REDIS_BACKEND = getenv('REDIS_BACKEND');
  15. if(!empty($REDIS_BACKEND)) {
  16. Resque::setBackend($REDIS_BACKEND);
  17. }
  18. // Set log level for resque-scheduler
  19. $logLevel = 0;
  20. $LOGGING = getenv('LOGGING');
  21. $VERBOSE = getenv('VERBOSE');
  22. $VVERBOSE = getenv('VVERBOSE');
  23. if(!empty($LOGGING) || !empty($VERBOSE)) {
  24. $logLevel = ResqueScheduler_Worker::LOG_NORMAL;
  25. }
  26. else if(!empty($VVERBOSE)) {
  27. $logLevel = ResqueScheduler_Worker::LOG_VERBOSE;
  28. }
  29. // Check for jobs every $interval seconds
  30. $interval = 5;
  31. $INTERVAL = getenv('INTERVAL');
  32. if(!empty($INTERVAL)) {
  33. $interval = $INTERVAL;
  34. }
  35. // Load the user's application if one exists
  36. $APP_INCLUDE = getenv('APP_INCLUDE');
  37. if($APP_INCLUDE) {
  38. if(!file_exists($APP_INCLUDE)) {
  39. die('APP_INCLUDE ('.$APP_INCLUDE.") does not exist.\n");
  40. }
  41. require_once $APP_INCLUDE;
  42. }
  43. $worker = new ResqueScheduler_Worker();
  44. $worker->logLevel = $logLevel;
  45. $PIDFILE = getenv('PIDFILE');
  46. if ($PIDFILE) {
  47. file_put_contents($PIDFILE, getmypid()) or
  48. die('Could not write PID information to ' . $PIDFILE);
  49. }
  50. fwrite(STDOUT, "*** Starting scheduler worker\n");
  51. $worker->work($interval);