server
server copied to clipboard
feat(TaskProcessingApi): Add endpoint for getting the next task
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
- Code is properly formatted
- Sign-off message is added to all commits
- [ ] Tests (unit, integration, api and/or acceptance) are included
- [ ] Screenshots before/after for front-end changes
- [ ] Documentation (manuals or wiki) has been updated or is not required
- [ ] Backports requested where applicable (ex: critical bugfixes)
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
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.
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:
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.
Would you go with another endpoint or change the current one?
We can add this to the current endpoint.
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
I didn't change the logic inside getNextScheduledTask - but it doesn't seem right to me for these reasons:
$task->setStatus(Task::STATUS_RUNNING);won't write anything to the database, right?- 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)
- I didn’t understand the logic at all why
$providerIdsis there as input and what it should do, that’s why I didn’t change the entry to atomic inside “getNextScheduledTask”
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'
Yeah I saw it, will fix all of it