CallQueuedHandler.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: yunwuxin <448901948@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace think\queue;
  12. use think\App;
  13. class CallQueuedHandler
  14. {
  15. protected $app;
  16. public function __construct(App $app)
  17. {
  18. $this->app = $app;
  19. }
  20. public function call(Job $job, array $data)
  21. {
  22. $command = unserialize($data['command']);
  23. $this->app->invoke([$command, 'handle']);
  24. if (!$job->isDeletedOrReleased()) {
  25. $job->delete();
  26. }
  27. }
  28. public function failed(array $data)
  29. {
  30. $command = unserialize($data['command']);
  31. if (method_exists($command, 'failed')) {
  32. $command->failed();
  33. }
  34. }
  35. }