laravel中队列异常捕获不到无法抛出?

代码如下:

public function handle()
    {
        $v = $this->params;
        $this->log(date('Y-m-d H:i:s'), 'check', '上传的id:' . $v->id . ',上传的录音地址:' . $v->MonitorFilename);
        try {
            $encodedURL = str_replace(['+', '/'], ['-', '_'], base64_encode($v->MonitorFilename));
            $encodedEntryURI = str_replace(['+', '/'], ['-', '_'], base64_encode($this->bucket));
            $url = '/fetch/' . $encodedURL . '/to/' . $encodedEntryURI;
            $token = $this->getAccessToken($url);
            $header = ['Host: iovip.qbox.me', 'Content-Type: application/x-www-form-urlencoded', 'Authorization: QBox ' . $token];
            $curl = curl_init();
            curl_setopt($curl, CURLOPT_URL, trim('http://iovip.qbox.me' . $url, "\n"));
            curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_POSTFIELDS, "");
            $result = json_decode(curl_exec($curl), true);
            curl_close($curl);
            $this->generateUrl($v->id, $result);
        } catch (Exception $e) {
            $this->log(date('Y-m-d H:i:s'), 'error', "天润话单上传失败.id=" . $v->id . $e->getMessage());
            throw new Exception($e);
        }
    }

写入failed_jobs表了,资源没请求到,应该抛出异常,但是日志中没有,求解!!!!

阅读 6.6k
3 个回答

查看下你的队列日志有没有记录该异常

因为程序执行到把任务加进队列时,并没有执行该队列,已就不会执行(handle,队列任务是由另一个进程执行的)方法,所以 laravel 日志中没错误记录

不知道是否是这个原因

clipboard.png
队列

php artisan queue:work --tries=3

Arguments:
connection The name of the queue connection to work

Options:

  --queue[=QUEUE]      The names of the queues to work
  --daemon             Run the worker in daemon mode (Deprecated)
  --once               Only process the next job on the queue
  --delay[=DELAY]      The number of seconds to delay failed jobs [default: "0"]
  --force              Force the worker to run even in maintenance mode
  --memory[=MEMORY]    The memory limit in megabytes [default: "128"]
  --sleep[=SLEEP]      Number of seconds to sleep when no job is available [default: "3"]
  --timeout[=TIMEOUT]  The number of seconds a child process can run [default: "60"]
  --tries[=TRIES]      Number of times to attempt a job before logging it failed [default: "0"]

-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version

  --ansi               Force ANSI output
  --no-ansi            Disable ANSI output

-n, --no-interaction Do not ask any interactive question

  --env[=ENV]          The environment the command should run under

-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
Start processing jobs on the queue as a daemon

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题