dereuromark / cakephp-queue

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

Inconsistent 'progress' datatype #406

Closed utdrmac closed 7 months ago

utdrmac commented 7 months ago

Ref: https://github.com/dereuromark/cakephp-queue/blob/master/docs/sections/queueing_jobs.md#updating-progressstatus

The first two code examples both use whole/integer number for progress representation:

   $queuedJobsTable->updateProgress($id, ($i + 1) / $totalRecords);

   $foo->doFirstPartOfTask();
   $queuedJobsTable->updateProgress($jobId, 33);

But then the 3rd code block says $progress = $job->progress; // A float from 0 to 1 This is not true. If you use an integer in ->updateProgress(), as the examples show, then ->progress is also returned as an integer.

The only instance where I've found that ->progress returns a "float" is when a job completes and the progress is updated inside QueuedJobsTable->markJobDone() to progress = 1.

Should the examples be updated to use floats to more accurately represent the end result? (ie: 0.33)

dereuromark commented 7 months ago

Feel free to fix up the docs

Ideally, I would imagine that the update method converts int to float, since that is a bit nicer to work with https://github.com/dereuromark/cakephp-queue/blob/29cf191fcf97ded7abe6fe9941d375964dc37dad/src/Model/Table/QueuedJobsTable.php#L675 We cannot change that now, so , yes, fixing docs is the best move

dereuromark commented 7 months ago

https://github.com/dereuromark/cakephp-queue/commit/bced5aa90024fc7c63f72d3956ed5fadef06a44f If there is anything else, feel free to directly PR it.