Lite.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace PhalApi\Task;
  3. use PhalApi\Task\MQ;
  4. use PhalApi\Exception\InternalServerErrorException;
  5. /**
  6. * 计划任务客户端类 PhalApi\Task\Lite
  7. *
  8. * @author dogstar <chanzonghuang@gmail.com> 20150516
  9. */
  10. class Lite {
  11. /**
  12. * PhalApi\Task\MQ $mq MQ队列
  13. */
  14. protected $mq;
  15. public function __construct(MQ $mq) {
  16. $this->mq = $mq;
  17. }
  18. /**
  19. * 添加一个计划任务到MQ队列
  20. * @param string $service 接口服务名称,如:Site.Index
  21. * @param array $params 接口服务参数
  22. */
  23. public function add($service, $params = array()) {
  24. if (empty($service) || count(explode('.', $service)) < 2) {
  25. return FALSE;
  26. }
  27. if (!is_array($params)) {
  28. return FALSE;
  29. }
  30. $rs = $this->mq->add($service, $params);
  31. if (!$rs) {
  32. \PhalApi\DI()->logger->debug('task add a new mq',
  33. array('service' => $service, 'params' => $params));
  34. return FALSE;
  35. }
  36. return TRUE;
  37. }
  38. }