Skip to content

Instantly share code, notes, and snippets.

@fredsted
Created July 24, 2019 12:12
Show Gist options
  • Save fredsted/846410708abd55459664e11136e7f297 to your computer and use it in GitHub Desktop.
Save fredsted/846410708abd55459664e11136e7f297 to your computer and use it in GitHub Desktop.
Retry all failed laravel jobs without causing a memory leak
<?php
$pdo = new PDO(
sprintf(
'mysql:host=%s;dbname=%s',
getenv('DB_HOST'),
getenv('DB_DATABASE')
),
getenv('DB_USERNAME'),
getenv('DB_PASSWORD')
);
$rows = $pdo->query('select id from failed_jobs')->fetchAll();
$count = count($rows);
echo sprintf("%d failed jobs found\n", $count);
foreach ($rows as $index => $row) {
echo sprintf(
"%08d/%08d: %s\n",
$index,
$count,
exec(sprintf('php artisan queue:retry %d', $row['id']))
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment