CJobs.Class.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace Jobs\Controller;
  3. use Mall\Framework\Factory;
  4. use Jobs\Controller\CBase;
  5. class CJobs extends CBase
  6. {
  7. private $logger=null;
  8. public function __construct($config)
  9. {
  10. $this->config = $config;
  11. $this->logger = Factory::logs($this->config['logPath'] ?:'', $this->config['logSaveFileApp'] ?:'', $this->config['app_name'] ?:'');
  12. }
  13. public function start($JobObject)
  14. {
  15. $jobClass =$JobObject->jobClass;
  16. $jobMethod=$JobObject->jobMethod;
  17. $jobParams=$JobObject->jobParams;
  18. try {
  19. $obj =new $jobClass();
  20. if (is_object($obj) && method_exists($obj, $jobMethod)) {
  21. $result = call_user_func([$obj, $jobMethod], $jobParams);
  22. $this->logger->log('topic run result: ' . $result, 'error');
  23. } else {
  24. $this->logger->log('Action obj not find: ' . json_encode($JobObject), 'error');
  25. }
  26. } catch (\Throwable $e) {
  27. catchError($this->logger, $e);
  28. } catch (\Exception $e) {
  29. catchError($this->logger, $e);
  30. }
  31. $this->logger->log('Action has been done, action content: ' . json_encode($JobObject));
  32. }
  33. }