Bug 35624 - Plugin tasks 'type' issue with plugins
Summary: Plugin tasks 'type' issue with plugins
Status: In Discussion
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal (vote)
Assignee: Tomás Cohen Arazi
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-12-20 22:15 UTC by Tomás Cohen Arazi
Modified: 2023-12-29 19:54 UTC (History)
5 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 35624: Allow jobs to pass a calculated job_type parameter (903 bytes, patch)
2023-12-20 22:17 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Tomás Cohen Arazi 2023-12-20 22:15:25 UTC
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.
Comment 1 Tomás Cohen Arazi 2023-12-20 22:17:58 UTC
Created attachment 160169 [details] [review]
Bug 35624: Allow jobs to pass a calculated job_type parameter
Comment 2 Tomás Cohen Arazi 2023-12-29 19:54:41 UTC
We also need to implement a way to have proper descriptions of those tasks, instead of the current "Unknown job type 'plugin_*'"