Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buried Jobs can't be fetched using getNextBuriedJob() #7

Open
GavIngram opened this issue Nov 21, 2024 · 1 comment
Open

Buried Jobs can't be fetched using getNextBuriedJob() #7

GavIngram opened this issue Nov 21, 2024 · 1 comment

Comments

@GavIngram
Copy link

It's not clear to me how to kick buried jobs back into the queue - I think this would be great to add into the example.

The way I've been trying (below) isn't working:

<?php
$Job_Queue = new n0nag0n\Job_Queue('mysql');
$PDO = new PDO('mysql:dbname=testdb;host=127.0.0.1', 'user', 'pass');
$Job_Queue->addQueueConnection($PDO);
$Job_Queue->watchPipeline('send_important_emails');

$Job_CheckBuriedInterval = 60; // 1 minute
$Job_LastBuriedCheckTime = time();

while (true) {
  $job = $Job_Queue->getNextJobAndReserve();

  if (empty($job)) {
    // check for buried jobs every minute
    if (time() - $Job_LastBuriedCheckTime >= $Job_CheckBuriedInterval) {
      $buriedJob = $Job_Queue->getNextBuriedJob();
      while (!empty($buriedJob)) {
        $Job_Queue->kickJob($buriedJob);
        $buriedJob = $Job_Queue->getNextBuriedJob();
      }
      $Job_LastBuriedCheckTime = time();
    }
    usleep(500000);
    continue;
  }

  echo "Processing {$job['id']}\n";
  $payload = json_decode($job['payload'], true);

  try {
    $result = doSomethingThatDoesSomething($payload);

    if ($result === true) {
      $Job_Queue->deleteJob($job);
    } else {
      $Job_Queue->buryJob($job);
    }
  } catch (Exception $e) {
    $Job_Queue->buryJob($job);
  }
}

I get the following error:

Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in /app/vendor/n0nag0n/simple-job-queue/src/Job_Queue.php:316
Stack trace:
#0 /app/vendor/n0nag0n/simple-job-queue/src/Job_Queue.php(316): PDOStatement->execute(Array)
#1 /var/www/html/scripts/worker.php(16): n0nag0n\Job_Queue->getNextBuriedJob()
#2 {main}
  thrown in /app/vendor/n0nag0n/simple-job-queue/src/Job_Queue.php on line 316
@n0nag0n
Copy link
Owner

n0nag0n commented Nov 23, 2024

I'll try to get to this in the next few days to see if I can replicate it. Thanks for reporting it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants