Malformed jobs prevent the queue from processing

Created on 8 May 2020, about 5 years ago
Updated 6 June 2025, 1 day ago

For reasons we have not yet been able to determine, we get jobs inserted to the database without a payload, randomly. These get stuck in processing and then error out. It gets constructed correctly, otherwise the Job constructor would error.

But yet we have a bad record saved

MariaDB [main]> select * from advancedqueue where payload = '';
+---------+------------+-----------------------------+---------+------------+---------+-------------+------------+-----------+------------+
| job_id  | queue_id   | type                        | payload | state      | message | num_retries | available  | processed | expires    |
+---------+------------+-----------------------------+---------+------------+---------+-------------+------------+-----------+------------+
| 1758950 | order_jobs | JOB_TYPE  |         | processing | NULL    |           0 | 1588427412 |         0 | 1588953615 |
+---------+------------+-----------------------------+---------+------------+---------+-------------+------------+-----------+------------+

Which gives us

/app/workers/../bin/drush advancedqueue:queue:process order_jobs: In Job.php line 99:
                              
  Missing property "payload"

πŸ€·β€β™‚οΈ So it's fine when we do

        $job = Job::create('JOB_TYPE', [
          'order_id' => $order->id(),
          'order_line_items' => $order_line_items,
        ]);
        $queue->enqueueJob($job);

But for some reason it enqueued and writes incorrectly. The only thing I can think of is that JSON encoding somehow fails?

From the Database enqueueJobs:

      $fields = $job->toArray();
      unset($fields['id']);
      $fields['payload'] = json_encode($fields['payload']);
      // InsertQuery supports inserting multiple rows at once, which is faster,
      // but that doesn't give us the inserted job IDs.
      $query = $this->connection->insert('advancedqueue')->fields($fields);

Regardless, the following should cause the job to fail, not halt queue processing

  public function __construct(array $definition) {
    foreach (['type', 'payload', 'state'] as $required_property) {
      if (empty($definition[$required_property])) {
        throw new \InvalidArgumentException(sprintf('Missing property "%s"', $required_property));
      }
    }
πŸ› Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024