Package Manager APIs: do not enqueue jobs directly.
Follow up of !59801 (comment 558606010)
Problem
In package managers APIs, we can have this need on the upload endpoint to enqueue a job for the uploaded package file.
Right now, we directly enqueue the job from the API class but this is not recommended (we disabled a cop rule).
The package file is created with the CreatePackageFileService
which is generic, which means that it is used for other package types that don't need to enqueue a job.
Proposal
We can't change CreatePackageFileService
as it is used by almost all package types. Instead, compose services to create the package file and enqueue the right job:
(Taking NuGet as an example)
- Create a
Nuget::CreatePackageFileService
. - Its
#execute
will- call the
CreatePackageFileService
- if the package file is created, enqueue the correct worker job
- call the
The API class can then simply use that new service the create the package file and enqueue a job at the same time.
MRs
Edited by Björn Holtvogt