dereuromark / cakephp-queue

Queue plugin for CakePHP - simple, pure PHP and without dependencies.
MIT License
306 stars 137 forks source link

why is $data empty? although there is data in the DB data column. #419

Closed acidhexe closed 4 months ago

acidhexe commented 4 months ago
namespace App\Queue\Task;

use Cake\Chronos\Chronos;
use Cake\Log\Log;
use Queue\Model\Entity\QueuedJob;
use Queue\Queue\Task;

class ExampleTask extends Task {
    public function run(array $data, int $jobId): void {

        Log::info('Running ExampleTask with Job ID: ' . $jobId);
        Log::debug('Data received:', $data);

        if (isset($data])) {
            $dataArray = json_decode($data, true);
            if (json_last_error() === JSON_ERROR_NONE) {
                $exampleValue = $dataArray['exampleKey'] ?? 'default';
                Log::info('Example value: ' . $exampleValue);
                // Hier erfolgt die eigentliche Verarbeitungslogik des Tasks
            }
            else {
                Log::error('JSON decode error: ' . json_last_error_msg());
            }
        }
        else {
            Log::error('No data received for the job.');
        }
        }
}
dereuromark commented 4 months ago

Check what $data directly holds, as very likely it is not inside $data['data'] etc

acidhexe commented 4 months ago

okay yes, I have $data is completely empty. $data[data] was just the last of countless attempts...

dereuromark commented 4 months ago

How do u fill it?

acidhexe commented 4 months ago
class QueueTestController extends AppController {
    public function addExampleJob() {
        // Füge den Job zur Queue hinzu
        $queue = TableRegistry::getTableLocator()->get('Queue.QueuedJobs');
        $queue->createJob('Example', ['exampleKey' => 'exampleValue']);

        // Bestätigungsnachricht setzen
        $this->Flash->success(__('The Example job has been added to the queue.'));

        // Weiterleitung zur Index-Seite oder wo auch immer du möchtest
        return $this->redirect(['action' => 'index']);
    }

    public function index() {
        // Hier kannst du deine Logik für die Index-Seite hinzufügen
    }
}

in data column: a:1:{s:10:"exampleKey";s:12:"exampleValue";}

Where is the data collected and passed on?

dereuromark commented 4 months ago

So if it is actually in there for saving, double check if the data is also still there when retreiving Check in DB, you can also see the payload inside the backend for in the view of a queue task

It sounds like it maybe cannot be persisted, possibly due to a wrong field type of the data column? Is it big enough (text) to hold all the data?

This sure is working for me and all the rest of the users, you can also see it working in the sandbox, so the issue must be on your side.

acidhexe commented 4 months ago

OK, I checked everything again and found the error, it was a , instead of a . when writing the logs. Sorry for the question and the inconvenience... thank you for your great work and your projects.