server icon indicating copy to clipboard operation
server copied to clipboard

feat(TaskProcessingApi): Add endpoint for getting the next task

Open provokateurin opened this issue 1 year ago • 7 comments
trafficstars

Summary

The ExApps need a way to get the next task. @marcelklehr I think there is a bug as the tasks are not marked as running when the getNextScheduledTask method of the service is called (or maybe it was also intentional and the endpoint should do it manually).

Checklist

provokateurin avatar May 17 '24 09:05 provokateurin

Ah, I missed this, yes.

@marcelklehr I think there is a bug as the tasks are not marked as running when the getNextScheduledTask method of the service is called (or maybe it was also intentional and the endpoint should do it manually).

Yeah, let's do this manually directly in the endpoint

marcelklehr avatar May 17 '24 11:05 marcelklehr

We need endpoint for getting nextTask by specifying multiple task_types. One provider can process multiple task types and we do not want to spam NC with one nextTask request for each task_type.

Or just to change string $taskTypeId to array of strings.

bigcat88 avatar Jun 05 '24 06:06 bigcat88

I don't see a reason why you would ever need to know the next task without also running it at the same time, but I can change it if you really want :woman_shrugging:

provokateurin avatar Jun 05 '24 08:06 provokateurin

I don't see a reason why you would ever need to know the next task without also running it at the same time

The synchronous background job will re-schedule itself based on the fact whether there is another job waiting to be executed.

marcelklehr avatar Jun 05 '24 08:06 marcelklehr

Would you go with another endpoint or change the current one?

We can add this to the current endpoint.

marcelklehr avatar Jun 05 '24 08:06 marcelklehr

ExApp needs to call these APIs to process tasks:

getNextScheduledTask getFileContents setProgress setResult

more precisely, there should be two versions of getFileContents - one for the UI with userId and other one for ExApp with [ExAppRequired] without checking for userId

cause only having those 4 endpoint ExApp can have no "system" flag to process tasks from what I see

bigcat88 avatar Jun 17 '24 14:06 bigcat88

I didn't change the logic inside getNextScheduledTask - but it doesn't seem right to me for these reasons:

  1. $task->setStatus(Task::STATUS_RUNNING); won't write anything to the database, right?
  2. Reading and writing to the database must be atomic within “getNextScheduledTask” (so that two requests for processing a task in parallel do not receive the same task)
  3. I didn’t understand the logic at all why $providerIds is there as input and what it should do, that’s why I didn’t change the entry to atomic inside “getNextScheduledTask”

bigcat88 avatar Jun 28 '24 14:06 bigcat88

btw Psalm failing is related:

Error: lib/private/TaskProcessing/Db/TaskMapper.php:25:7: InvalidTemplateParam: Extended template param T expects type OCP\AppFramework\Db\Entity, type OCP\TaskProcessing\Task given (see https://psalm.dev/183)
Error: lib/private/TaskProcessing/Db/TaskMapper.php:42:15: UndefinedPropertyFetch: Static property OCP\TaskProcessing\Task::$columns is not defined (see https://psalm.dev/039)
Error: lib/private/TaskProcessing/Db/TaskMapper.php:57:15: UndefinedPropertyFetch: Static property OCP\TaskProcessing\Task::$columns is not defined (see https://psalm.dev/039)
Error: lib/private/TaskProcessing/Db/TaskMapper.php:89:15: UndefinedPropertyFetch: Static property OCP\TaskProcessing\Task::$columns is not defined (see https://psalm.dev/039)
Error: lib/private/TaskProcessing/Db/TaskMapper.php:109:15: UndefinedPropertyFetch: Static property OCP\TaskProcessing\Task::$columns is not defined (see https://psalm.dev/039)
Error: lib/private/TaskProcessing/Db/TaskMapper.php:130:15: UndefinedPropertyFetch: Static property OCP\TaskProcessing\Task::$columns is not defined (see https://psalm.dev/039)
Error: lib/private/TaskProcessing/Db/TaskMapper.php:152:32: ImplementedParamTypeMismatch: Argument 1 of OC\TaskProcessing\Db\TaskMapper::update has wrong type 'OCP\AppFramework\Db\Entity', expecting 'OCP\TaskProcessing\Task' as defined by OCP\AppFramework\Db\QBMapper::update (see https://psalm.dev/199)
Error: lib/private/TaskProcessing/Manager.php:584:29: InvalidArgument: Argument 1 of OC\TaskProcessing\Db\TaskMapper::insert expects OCP\TaskProcessing\Task, but OC\TaskProcessing\Db\Task provided (see https://psalm.dev/004)
Error: lib/private/TaskProcessing/Manager.php:595:29: InvalidArgument: Argument 1 of OC\TaskProcessing\Db\TaskMapper::delete expects OCP\TaskProcessing\Task, but OC\TaskProcessing\Db\Task provided (see https://psalm.dev/004)
Error: lib/private/TaskProcessing/Manager.php:601:24: UndefinedMethod: Method OCP\TaskProcessing\Task::toPublicTask does not exist (see https://psalm.dev/022)
Error: lib/private/TaskProcessing/Manager.php:619:30: InvalidArgument: Argument 1 of OC\TaskProcessing\Db\TaskMapper::update expects OCP\TaskProcessing\Task, but OC\TaskProcessing\Db\Task provided (see https://psalm.dev/004)
Error: lib/private/TaskProcessing/Manager.php:635:30: InvalidArgument: Argument 1 of OC\TaskProcessing\Db\TaskMapper::update expects OCP\TaskProcessing\Task, but OC\TaskProcessing\Db\Task provided (see https://psalm.dev/004)
Error: lib/private/TaskProcessing/Manager.php:684:30: InvalidArgument: Argument 1 of OC\TaskProcessing\Db\TaskMapper::update expects OCP\TaskProcessing\Task, but OC\TaskProcessing\Db\Task provided (see https://psalm.dev/004)
Error: lib/private/TaskProcessing/Manager.php:699:24: UndefinedMethod: Method OCP\TaskProcessing\Task::toPublicTask does not exist (see https://psalm.dev/022)
Error: lib/private/TaskProcessing/Manager.php:771:24: UndefinedMethod: Method OCP\TaskProcessing\Task::toPublicTask does not exist (see https://psalm.dev/022)
Error: lib/private/TaskProcessing/Manager.php:784:60: UndefinedMethod: Method OCP\TaskProcessing\Task::toPublicTask does not exist (see https://psalm.dev/022)
Error: lib/private/TaskProcessing/Manager.php:795:60: UndefinedMethod: Method OCP\TaskProcessing\Task::toPublicTask does not exist (see https://psalm.dev/022)
Error: lib/public/AppFramework/Db/QBMapper.php:153:18: MismatchingDocblockParamType: Parameter $entity has wrong type 'OCP\TaskProcessing\Task', should be 'OCP\AppFramework\Db\Entity'

nickvergessen avatar Jul 01 '24 14:07 nickvergessen

Yeah I saw it, will fix all of it

provokateurin avatar Jul 01 '24 14:07 provokateurin