When we designed the 'background jobs for plugins', we let the plugins define a `namespace` and each of it's jobs, a `type`. Plugins pick a name and provide a mapping to the implementing class, and then Koha's core handling calculates a plugin-specific type, to avoid collisions, in the form of "plugin_$namespace_$type'. This works correctly for picking the job from the DB, which is what we probably tested. The problem I found is the Koha::BackgroundJob::enqueue method doesn't have enough information to calculate the 'job_type'. For that it would need to: * know we're talking about a plugin job * know which plugin and/or the namespace * know how to calculate the name Right now, it picks the type from $self->job_ype. The simplest workaround for this situation would be (a) to do something like: --- a/Koha/BackgroundJob.pm +++ b/Koha/BackgroundJob.pm @@ -95,12 +95,12 @@ Return the job_id of the newly created job. sub enqueue { my ( $self, $params ) = @_; - my $job_type = $self->job_type; + my $job_type = $params->{job_type} // $self->job_type; and thus allow the plugin to deal with the calculation. The drawback being we give too much responsibility to the plugin author and less flexibility if we find we need to change this. I'm really not sure how bad it would be. Sounds reasonable. Another option would be (b) to require plugin authors to put the fully qualified job type on their plugins [1], and get rid of doing it in Koha::BackgroundJob::plugin_types_to_classes. A third option would be to pass the information about the job coming from a plugin (e.g. enqueue({ is_plugin => 1, plugin_namespage => 'kitchensink' }) and have some internal sub to calculate the final 'type'. Posting this to start the discussion, but I need to finish implementing plugin jobs this week so, hurry! [1] This is what we actually did on the KitchenSink plugin.
Created attachment 160169 [details] [review] Bug 35624: Allow jobs to pass a calculated job_type parameter
We also need to implement a way to have proper descriptions of those tasks, instead of the current "Unknown job type 'plugin_*'"