Implement taskprocessing:worker occ command#59015
Open
Conversation
Co-authored-by: marcelklehr <986878+marcelklehr@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add OCC command for task processing worker
Add Mar 17, 2026
occ taskprocessing:worker dedicated synchronous task processing command
Co-authored-by: marcelklehr <986878+marcelklehr@users.noreply.github.com>
Copilot
AI
changed the title
Add
Add Mar 17, 2026
occ taskprocessing:worker dedicated synchronous task processing command--taskTypes whitelist option to taskprocessing:worker
Co-authored-by: marcelklehr <986878+marcelklehr@users.noreply.github.com>
Copilot
AI
changed the title
Add
taskprocessing:worker: add --taskTypes whitelist option
Mar 17, 2026
--taskTypes whitelist option to taskprocessing:worker
marcelklehr
reviewed
Mar 17, 2026
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors |
Member
There was a problem hiding this comment.
Suggested change
| * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | |
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
marcelklehr
reviewed
Mar 17, 2026
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors |
Member
There was a problem hiding this comment.
Suggested change
| * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | |
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
Copilot stopped work on behalf of
marcelklehr due to an error
March 17, 2026 20:50
Copilot stopped work on behalf of
marcelklehr due to an error
March 17, 2026 22:04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
adds a dedicated OCC worker loop for synchronous TaskProcessing providers, plus unit tests and command registration.
What changed (files)
core/Command/TaskProcessing/WorkerCommand.phpcore/register_command.php(registers the new command)lib/composer/composer/autoload_classmap.phplib/composer/composer/autoload_static.phptests/Core/Command/TaskProcessing/WorkerCommandTest.phpWhat the new command does
Introduces:
occ taskprocessing:workerIt runs a loop that repeatedly tries to process exactly one scheduled TaskProcessing task per iteration (one task at a time per process), using the same “preferred synchronous provider” logic as
OC\TaskProcessing\SynchronousBackgroundJob, but without scheduling/re-adding background jobs.Core behavior:
IManager::getProviders()ISynchronousProvidergetPreferredProvider($taskTypeId), compare provider IDs)getNextScheduledTask([$taskTypeId])NotFoundException: no task → continueException: log error → continueprocessTask($task, $provider)If no task was processed in an iteration, it sleeps for the configured interval.
It also calls
abortIfInterrupted()(fromOC\Core\Command\Base) to stop cleanly on SIGTERM/SIGINT, printing “Task processing worker stopped”.Verbose output prints lines like:
CLI options
--timeout/-t(default0): stop after N seconds;0means run indefinitely.--interval/-i(default1): sleep time (seconds) when no task was processed.--once: process at most one task then exit (handy for testing/one-shot runs).--taskTypes(repeatable array): only process tasks for the given task type IDs; providers whosegetTaskTypeId()isn’t in the list are skipped.Tests added
tests/Core/Command/TaskProcessing/WorkerCommandTest.phpadds a fairly comprehensive unit-test suite around the command loop behavior using mocks forIManager,LoggerInterface, and provider interfaces, including:--onceexits when no providers/tasks--onceprocesses a single task end-to-endISynchronousProviderprovidersNotFoundException(no task) without callingprocessTaskException--taskTypeswhitelist filtering cases (match-only, no match, empty whitelist)Notes / things you may want to review
processTask()(it calls it but doesn’t branch on true/false). SBJ uses the boolean to decide whether to reschedule; for this worker it may be fine, but it’s a behavioral difference worth validating.If you want, I can also point out a couple of small potential improvements (argument validation for negative interval/timeout, printing timeout message only in verbose, etc.), but the above is what the PR currently implements.
Checklist
3. to review, feature component)stable32)AI (if applicable)
Original prompt
Create a PR on
nextcloud/server(base branch:master) adding a new OCC commandtaskprocessing:workerthat behaves like a dedicated worker for TaskProcessing synchronous providers, without relying on the background job queue.Context
lib/private/TaskProcessing/SynchronousBackgroundJob.php(commit shown in conversation) processes TaskProcessing tasks for providers that implementOCP\TaskProcessing\ISynchronousProvider, but as aQueuedJobit is removed from the jobs table during execution and re-added viaIJobList::add(), which can lead to timing-dependent parallelism when usingocc background-job:workerwith multiple workers.SynchronousBackgroundJob::run()does, running in a loop.Requirements
core/namedocc taskprocessing:worker.--timeout=<seconds>: integer seconds.0(or omitted) means run indefinitely.--interval=<seconds>: sleep duration when no task was processed in an iteration; default should be reasonable (e.g. 1). Should be integer seconds.--onceto process at most one task then exit (nice to have, but not required unless it helps testing).OC\TaskProcessing\SynchronousBackgroundJob::run($argument):IManager::getProviders().ISynchronousProvider.IManager::getPreferredProvider($taskTypeId)and compare IDs).IManager::getNextScheduledTask([$taskTypeId]).NotFoundException: no task for that task type; continue.OCP\TaskProcessing\Exception\Exception: log error and continue.IManager::processTask($task, $provider).--intervalseconds to avoid a busy loop.Psr\Log\LoggerInterfacefor errors similar to SBJ.IManager, providers, and verifying loop behavior / timeout / interval / preferred provider filtering). Keep tests fast.Implementation hints
core/Command/Background/JobWorker.phpfor structure (timeout/interval/once patterns). Reuse similar patterns.Deliverables
core/Command/TaskProcessing/(or similar appropriate location) with nametaskprocessing:worker.occ taskprocessing:workeris available.The following is the prior conversation context from the user's chat exploration (may be truncated):
User: As I see it, the synchronous background job is added to the job list in the taskprocessing manager upon scheduling a task, but can there be multiple entries of the same backgroundjob class in the job list? If not then, the second task will never be executed, I think. Is that correct?
Assistant: No — your conclusion (“if not, then the second task will never be executed”) is not correct for Nextcloud’s background job system as implemented here.
Can there be multiple entries of the same backgroundjob class in the job list?
Not for the same
(class, argument)pair.In
lib/private/BackgroundJob/JobList.php,IJobList::add()does this:$class(the job class name)$argumentJson = json_encode($argument)argument_hash = hash('sha256', $argumentJson)has($job, $argument):has()queries thejobstable for a row with same class and same argument_hash.reserved_at,last_checked,last_run.So “enqueue again” typically means “make sure there is a job row present and runnable”, not “add a second copy”.
Does that mean a newly scheduled “...
This pull request was created from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.