-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add background_tasks implementation example
Signed-off-by: Tomas Cohen Arazi <[email protected]>
- Loading branch information
1 parent
da5b15b
commit 30d1446
Showing
4 changed files
with
160 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package Koha::Plugin::Com::ByWaterSolutions::KitchenSink::Greeter; | ||
|
||
# This file is part of Koha. | ||
# | ||
# Koha is free software; you can redistribute it and/or modify it | ||
# under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Koha is distributed in the hope that it will be useful, but | ||
# WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with Koha; if not, see <http://www.gnu.org/licenses>. | ||
|
||
use Modern::Perl; | ||
|
||
use base 'Koha::BackgroundJob'; | ||
|
||
=head1 NAME | ||
KitchenSink::Greeter - Background task for greeting in the logs | ||
This is a subclass of Koha::BackgroundJob. | ||
=head1 API | ||
=head2 Class methods | ||
=head3 job_type | ||
Define the job type of this job: greeter | ||
=cut | ||
|
||
sub job_type { | ||
return 'plugin_kitchensink_greeter'; | ||
} | ||
|
||
=head3 process | ||
Process the modification. | ||
=cut | ||
|
||
sub process { | ||
my ( $self, $args ) = @_; | ||
|
||
$self->start; | ||
|
||
my @messages; | ||
my $report = { | ||
total_greets => $self->size, | ||
total_success => 0, | ||
}; | ||
|
||
foreach my $step ( 1 .. $self->size ) { | ||
|
||
warn "Greeting: Hola! ($step)"; | ||
|
||
push @messages, | ||
{ | ||
type => 'success', | ||
code => 'greeted', | ||
}; | ||
|
||
$report->{total_success}++; | ||
|
||
$self->step; | ||
} | ||
|
||
my $data = $self->decoded_data; | ||
$data->{messages} = \@messages; | ||
$data->{report} = $report; | ||
|
||
$self->finish($data); | ||
} | ||
|
||
=head3 enqueue | ||
Enqueue the new job | ||
=cut | ||
|
||
sub enqueue { | ||
my ( $self, $args ) = @_; | ||
|
||
$self->SUPER::enqueue( | ||
{ | ||
job_size => $args->{size} // 5, | ||
job_args => {}, | ||
} | ||
); | ||
} | ||
|
||
1; |
15 changes: 15 additions & 0 deletions
15
Koha/Plugin/Com/ByWaterSolutions/KitchenSink/greets_scheduled.tt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[% INCLUDE 'doc-head-open.inc' %] | ||
<title>Koha: Kitchen Sink Plugin: Example background job scheduling</title> | ||
[% INCLUDE 'doc-head-close.inc' %] | ||
</head> | ||
<body> | ||
[% INCLUDE 'header.inc' %] | ||
[% INCLUDE 'cat-search.inc' %] | ||
|
||
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/plugins/plugins-home.pl">Plugins</a> › Kitchen Sink › Example Tool</div> | ||
|
||
<div id="doc3"> | ||
|
||
<p>Hello! You scheduled [% count | html %] greetings!</p> | ||
|
||
[% INCLUDE 'intranet-bottom.inc' %] |
This file contains 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