Laravel Queued Job doesn't wait for exec to coplete

╄→гoц情女王★ 提交于 2019-12-24 15:15:12

问题


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)

My closure is:

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();
        });

and it seems to skip straight through the exec line, although i do think it is still being run.

Note, if i change the driver back to sync then it all runs completely fine (but obviously not in a queue)

Any idea how to wait for exec?


回答1:


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));

Was providing a url that just had localhost rather than localhost:8888

So i've hacked it to do a string replace for localhost.

Not sure why putting it into a queue would cause laravel to provide incorrect urls. But at least it's working!



来源:https://stackoverflow.com/questions/32460886/laravel-queued-job-doesnt-wait-for-exec-to-coplete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!