dereuromark / cakephp-queue

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

Documentation not updated to CakePHP5 #403

Closed utdrmac closed 7 months ago

utdrmac commented 7 months ago

Trying to use this plugin by following the documentation. I first did the basic setup, I added the addPlugin() in my src/Application.php::bootstrap(), I added my config to config/app_local.php, I ran the migration to create the db tables, and now I'm trying to create a job.

In my controller,

class PreviewController extends AppController
{
...
        public function export(string $project_id): \Cake\Http\Response
    {
        $this->loadModel('Queue.QueuedJobs');

        // Create the task
        $jobId = $this->QueuedJobs->createJob(ExportNotionDocTask::class, ['project_id' => $project_id]);
        }
}

Call to undefined method App\Controller\PreviewController::loadModel()

What now? loadModel() only exists in CakePHP4. Can you please update the documentation for CakePHP5?

utdrmac commented 7 months ago

Reading your example code for the sandbox, I found references to a ModelAwareTrait. Searching Cake docs, I discovered the usage. I am now doing this:

use Cake\Datasource\ModelAwareTrait;
use App\Queue\Task\ExportNotionDocTask;

class PreviewController extends AppController
{
        use ModelAwareTrait; // For loading the Queue model
...
        public function export(string $project_id): \Cake\Http\Response
    {
        // Load the ORM model of the queue
        $queue = $this->fetchModel('Queue.QueuedJobs');

        // Create the task
        $jobId = $queue->createJob(ExportNotionDocTask::class, ['project_id' => $project_id]);
        }
}

And this seems to work. I can at least see new records being added to the database table. It would be nice to see the documentation updated with more explanation for CakePHP5 usage.

utdrmac commented 7 months ago

Also, the docs give this example in your controller:

use Queue\Queue\Task\EmailTask;

Assuming you created your task at src/Queue/Task/MyCoolTask.php, using the bake queue_task MyCoolTask command, the above is incorrect. You have to use use App\Queue\Task\MyCoolTask

dereuromark commented 7 months ago

Feel free to make a PR ti improve docs

utdrmac commented 7 months ago

I don't know enough about this to make doc improvements. Since the docs are out of date, I'm basically shooting in the dark, trying to see what works. That's not the right way to code, nor the right way to create docs. I would expect "This branch is for use with CakePHP 5.0+." to contain documentation for 5.0.

dereuromark commented 7 months ago

I fixed what I found: https://github.com/dereuromark/cakephp-queue/commit/29cf191fcf97ded7abe6fe9941d375964dc37dad

If there is anything else left, please click edit on the page (top right) and modify + PR the changes. Thank you.