Bug 39772: Extend background_tasks API to allow for human-readable job names

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Jesse Maseto <jesse@bywatersolutions.com>
This commit is contained in:
Tadeusz „tadzik” Sośnierz 2025-04-30 12:09:46 +02:00 committed by Jesse Maseto
parent a368406305
commit c7cf695279
No known key found for this signature in database
GPG Key ID: 4D16BFCF78FFFDEC
4 changed files with 32 additions and 23 deletions

View File

@ -471,14 +471,17 @@ sub plugin_types_to_classes {
my $namespace = $metadata->{namespace};
foreach my $type ( keys %{$tasks} ) {
my $class = $tasks->{$type};
my $class =
( ref $tasks->{$type} eq 'HASH' )
? $tasks->{$type}{class}
: $tasks->{$type};
# skip if conditions not met
next unless $type and $class;
my $key = "plugin_$namespace" . "_$type";
$self->{_plugin_mapping}->{$key} = $tasks->{$type};
$self->{_plugin_mapping}->{$key} = $class;
}
}
}

View File

@ -91,9 +91,12 @@ my @plugin_job_types;
for my $plugin (@plugins) {
my $tasks = $plugin->background_tasks;
for my $id ( keys %$tasks ) {
# fallback to package name if no human-readable name is available
my $name = ( ref $tasks->{$id} eq 'HASH' ) ? $tasks->{$id}{name} : $tasks->{$id};
push @plugin_job_types, {
id => 'plugin_' . $plugin->get_metadata->{namespace} . "_$id",
str => $tasks->{$id},
str => $name,
};
}
}

View File

@ -181,72 +181,72 @@
const job_types = [
{
'_id': 'batch_biblio_record_modification',
'_str': _("Batch bibliographic record modification")
'_str': _("Batch bibliographic record modification").escapeHtml()
},
{
'_id': 'batch_biblio_record_deletion',
'_str': _("Batch bibliographic record deletion")
'_str': _("Batch bibliographic record deletion").escapeHtml()
},
{
'_id': 'batch_authority_record_modification',
'_str': _("Batch authority record modification")
'_str': _("Batch authority record modification").escapeHtml()
},
{
'_id': 'batch_authority_record_deletion',
'_str': _("Batch authority record deletion")
'_str': _("Batch authority record deletion").escapeHtml()
},
{
'_id': 'batch_item_record_modification',
'_str': _("Batch item record modification")
'_str': _("Batch item record modification").escapeHtml()
},
{
'_id': 'batch_item_record_deletion',
'_str': _("Batch item record deletion")
'_str': _("Batch item record deletion").escapeHtml()
},
{
'_id': 'erm_sushi_harvester',
'_str': _("ERM Usage Statistics SUSHI Harvester")
'_str': _("ERM Usage Statistics SUSHI Harvester").escapeHtml()
},
{
'_id': 'batch_hold_cancel',
'_str': _("Batch hold cancellation")
'_str': _("Batch hold cancellation").escapeHtml()
},
{
'_id': 'pseudonymize_statistic',
'_str': _("Pseudonymize statistic")
'_str': _("Pseudonymize statistic").escapeHtml()
},
{
'_id': 'create_eholdings_from_biblios',
'_str': _("Create eHolding titles")
'_str': _("Create eHolding titles").escapeHtml()
},
{
'_id': 'update_elastic_index',
'_str': _("Update Elasticsearch index")
'_str': _("Update Elasticsearch index").escapeHtml()
},
{
'_id': 'update_holds_queue_for_biblios',
'_str': _("Holds queue update")
'_str': _("Holds queue update").escapeHtml()
},
{
'_id': 'stage_marc_for_import',
'_str': _("Staged MARC records for import")
'_str': _("Staged MARC records for import").escapeHtml()
},
{
'_id': 'marc_import_commit_batch',
'_str': _("Import MARC records")
'_str': _("Import MARC records").escapeHtml()
},
{
'_id': 'marc_import_revert_batch',
'_str': _("Revert import MARC records")
'_str': _("Revert import MARC records").escapeHtml()
},
{
'_id': 'import_from_kbart_file',
'_str': _("Import titles from a KBART file")
'_str': _("Import titles from a KBART file").escapeHtml()
},
[% FOR job_type IN plugin_job_types %]
{
'_id': '[% job_type.id %]',
'_str': '[% job_type.str %]'
'_id': '[% job_type.id | html %]',
'_str': '[% job_type.str | html_entity %]'
},
[% END %]
];
@ -316,7 +316,7 @@
"searchable": true,
"orderable": true,
"render": function(data, type, row, meta) {
return get_job_type(row.type).escapeHtml();
return get_job_type(row.type);
}
},
{

View File

@ -365,7 +365,10 @@ sub intranet_catalog_biblio_tab {
sub background_tasks {
return {
foo => 'MyPlugin::Class::Foo',
bar => 'MyPlugin::Class::Bar',
bar => {
class => 'MyPlugin::Class::Bar',
name => "Bar task",
},
};
}