namespace App\Jobs;
use App\Models\FluidbookDocument;
+use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
class FluidbookDocumentFileProcess extends Base
protected $forceCheck;
protected $forceProcess;
- protected $finish = false;
-
protected $path = "";
protected $log = '';
public function handle()
{
- $this->finish = false;
try {
echo $this->document->getFile($this->page, $this->format, $this->resolution, $this->quality, $this->withText, $this->withGraphics, $this->version, $this->forceCheck, $this->forceProcess) . "\n";
} catch (\Exception $e) {
Log::warning($e->getMessage());
$this->log = $e->getMessage();
}
- $this->finish = true;
+ $this->setFinish();
+ }
+
+ public function setFinish($finish = true)
+ {
+ Cache::put('job_' . $this->path, $finish, 300);
+ }
+
+
+ public function isFinish()
+ {
+ return Cache::get('job_' . $this->path, false);
}
/**
* @return boolean
*/
- public function isDone($forceCheck = false, $checkFile = true)
+ public function isDone($forceCheck = false)
{
- return $this->finish || ($checkFile && $this->isOK($forceCheck));
+ return $this->isFinish() || $this->isOK($forceCheck);
}
public function isOK($forceCheck = false)
['svg', 150, true, false, 'html'],
];
- Log::debug('Sync ? ' . $sync);
-
$nbfiles = count($files);
for ($i = 1; $i <= $this->pages; $i++) {
foreach ($files as $file) {
$jobs[] = $job;
if ($sync) {
- $this->_checkJobs($uploadID, $jobs, $nbfiles, true);
+ $this->_checkJobs($uploadID, $jobs, $nbfiles);
}
}
- if (!$sync && $i % 4 === 0) {
- $this->_checkJobs($uploadID, $jobs, $nbfiles, false);
+ if (!$sync) {
+ $this->_checkJobs($uploadID, $jobs, $nbfiles);
}
}
while (true) {
- if ($this->_checkJobs($uploadID, $jobs, $nbfiles, true) === 1) {
+ if ($this->_checkJobs($uploadID, $jobs, $nbfiles) === 1) {
return;
}
- usleep(0.25 * 1000000);
+ usleep(5 * 1000000);
}
}
Farm::extractLinks($this->getPDFSource(), $this->path());
}
- protected function _checkJobs($uploadID, $jobs, $nbfiles, $checkFile = true)
+ protected function _checkJobs($uploadID, $jobs, $nbfiles)
{
$this->checkInfos();
$nbjobs = $nbfiles * $this->pages;
$done = 0;
foreach ($jobs as $job) {
/** @var $job FluidbookDocumentFileProcess */
- if ($job->isDone(false, $checkFile)) {
+ if ($job->isDone()) {
$done++;
}
}
public function checkInfos($force = false)
{
if ($force || null === $this->pdf_data) {
- Log::debug('check document infos');
$infos = $this->_getInfos();
$this->pages = $infos->pages;