Laravel排队作业不等待exec完成 [英] Laravel Queued Job doesn't wait for exec to coplete
问题描述
我已经建立并运行了队列(作业得以运行),但是脚本似乎并没有等待我的exec行运行,而是继续执行下一行代码.
i have my queues set up and working (the jobs get run), however the script doesn't seem to wait for my exec line to run before progressing with the next line of code.
这意味着我在接下来的几行中遇到了异常(因为它正在寻找尚未生成的文件)
This means i'm getting exceptions in the next few lines (because it's looking for a file that hasn't been produced yet)
我的结案是:
Queue::push(function($job) use ($gid,$eid)
{
$phantomLoc = base_path()."/vendor/bin/phantomjs";
$scriptLoc = app_path()."/libraries/makeVideo.js";
$pageAddress = route('image_maker_video', array($gid,$eid));
$imageName = base_path().'/../data/team_images/'.$gid.'/video-sheets/'.$eid."/";
$execString = $phantomLoc.' '.$scriptLoc.' '.$pageAddress.' '.$imageName;
//empty the folder first
Helpers::emptyFolder($imageName);
exec($execString, $return_array, $return_value);
if ($return_value == 0) {
//now convert image sequence to video
$outputPath = base_path().'/../data/team_images/'.$gid.'/video-sheets/'.$eid;
$return_value = Helpers::PNGsToVideo($imageName, $outputPath);
if ($return_value == 0) {
//it worked!!
Helpers::emptyFolder($imageName);
//rmdir($imageName);
return "video in progress";
return Redirect::to('/team_images/'.$gid.'/video-sheets/'.$eid.".mkv");
} else {
Log::error($return_value." - ffmpeg return val");
abort(500, $return_value." - ffmpeg return val");
}
} else {
Log::error($return_value." - video phantom return val");
abort(500, $return_value." - video phantom return val");
}
$job->delete();
});
,尽管我确实认为它仍在运行,但它似乎直接跳过了exec
行.
and it seems to skip straight through the exec
line, although i do think it is still being run.
请注意,如果我将驱动程序改回sync
,则所有驱动程序都可以正常运行(但显然不在队列中)
Note, if i change the driver back to sync
then it all runs completely fine (but obviously not in a queue)
有什么办法等待exec
吗?
推荐答案
事实证明exec
正在出错,但是错误(来自phatomjs)给出了返回码0.
It turns out that exec
was erroring out, but the error (from phatomjs)gave a return code of 0.
事实证明,错误是因为该行
Turns out that the error was because the line
$pageAddress = route('image_maker_video', array($gid,$eid));
提供的网址仅包含localhost
而不是localhost:8888
Was providing a url that just had localhost
rather than localhost:8888
所以我已经破解了它,以代替本地主机的字符串.
So i've hacked it to do a string replace for localhost.
不确定为什么将其放入队列会导致laravel提供不正确的网址.但是至少可以正常工作!
Not sure why putting it into a queue would cause laravel to provide incorrect urls. But at least it's working!
这篇关于Laravel排队作业不等待exec完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!