Worker : simplification — pagedjs-cli ne stream pas la progression page par page hors TTY
All checks were successful
Deploy / deploy (push) Successful in 16s
All checks were successful
Deploy / deploy (push) Successful in 16s
ora désactive le spinner par-page hors TTY et émet seulement 'Rendering: Page 1' puis directement 'Rendering N pages took…'. Sans indicateur de progression réel possible, on retire le streaming (proc_open) et on revient à exec() simple. Le worker écrit maintenant rendering/done uniquement. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
db74e27c3a
commit
56f5a45b7d
2 changed files with 10 additions and 96 deletions
32
worker.php
32
worker.php
|
|
@ -50,42 +50,16 @@ set_time_limit(0); // Le worker tourne en arrière-plan, pas de limite
|
|||
$generator = new \Web2Print\Services\PdfGenerator($config);
|
||||
$pdfPath = $jobs->pdfPath($jobId);
|
||||
|
||||
$pageCount = 0;
|
||||
$debugLog = $config['log_file'];
|
||||
$logLine = function (string $msg) use ($debugLog, $jobId) {
|
||||
@file_put_contents($debugLog, '[' . date('Y-m-d H:i:s.u') . '] [job ' . $jobId . '] ' . $msg . "\n", FILE_APPEND);
|
||||
};
|
||||
$logLine('worker start, url=' . ($request['url'] ?? '?'));
|
||||
|
||||
$onProgress = function (string $line) use ($jobs, $jobId, &$pageCount, $logLine) {
|
||||
$logLine('stdout: ' . $line);
|
||||
// pagedjs-cli utilise ora qui peut émettre via \r ; on a déjà découpé.
|
||||
// Lignes typiques : "- Loading: ...", "✔ Loaded", "- Rendering: Page X"
|
||||
if (preg_match('/Rendering:\s*Page\s*(\d+)/i', $line, $m)) {
|
||||
$pageCount = max($pageCount, (int)$m[1]);
|
||||
$jobs->writeStatus($jobId, [
|
||||
'status' => 'rendering',
|
||||
'page' => $pageCount,
|
||||
]);
|
||||
} elseif (stripos($line, 'Loaded') !== false) {
|
||||
$jobs->writeStatus($jobId, ['status' => 'rendering', 'page' => 0]);
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
$jobs->writeStatus($jobId, ['status' => 'rendering', 'page' => 0]);
|
||||
$jobs->writeStatus($jobId, ['status' => 'rendering']);
|
||||
|
||||
$generator->generateFromUrlToFile(
|
||||
$request['url'],
|
||||
$pdfPath,
|
||||
$request['options'] ?? [],
|
||||
$onProgress
|
||||
$request['options'] ?? []
|
||||
);
|
||||
|
||||
$jobs->writeStatus($jobId, [
|
||||
'status' => 'done',
|
||||
'pages' => $pageCount,
|
||||
]);
|
||||
$jobs->writeStatus($jobId, ['status' => 'done']);
|
||||
} catch (\Throwable $e) {
|
||||
$jobs->writeStatus($jobId, [
|
||||
'status' => 'error',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue