@@ -, +, @@
---
debian/docs/koha-common.xml | 8 ++
debian/koha-common.init | 3 +
debian/scripts/koha-create | 3 +
debian/scripts/koha-disable | 3 +
debian/scripts/koha-functions.sh | 14 +++
debian/scripts/koha-remove | 4 +
debian/scripts/koha-worker | 242 +++++++++++++++++++++++++++++++++++++++
misc/background_jobs_worker.pl | 52 +++++++++
8 files changed, 329 insertions(+)
create mode 100755 debian/scripts/koha-worker
create mode 100755 misc/background_jobs_worker.pl
--- a/debian/docs/koha-common.xml
+++ a/debian/docs/koha-common.xml
@@ -138,7 +138,15 @@
Manage the indexer daemon for named Koha instances.
+
+
+
+
+ Manage the worker daemon for named Koha instances.
+
+
+
--- a/debian/koha-common.init
+++ a/debian/koha-common.init
@@ -62,6 +62,7 @@ do_start()
koha-sip --start $(koha-list --enabled --sip)
koha-plack --start $(koha-list --enabled --plack)
koha-z3950-responder --start --quiet $(koha-list --enabled --z3950)
+ koha-worker --start $(koha-list --enabled)
if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
koha-indexer --start --quiet $(koha-list --enabled)
@@ -78,6 +79,7 @@ do_stop()
koha-sip --stop $(koha-list --sip)
koha-plack --stop --quiet $(koha-list --enabled --plack)
koha-z3950-responder --stop --quiet $(koha-list --enabled --z3950)
+ koha-worker --stop --quiet $(koha-list --enabled)
if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
koha-indexer --stop --quiet $(koha-list --enabled)
@@ -92,6 +94,7 @@ do_reload() {
koha-sip --restart $(koha-list --enabled --sip)
koha-plack --restart --quiet $(koha-list --enabled --plack)
koha-z3950-responder --restart --quiet $(koha-list --enabled --z3950)
+ koha-worker --restart --quiet $(koha-list --enabled)
if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
koha-indexer --restart --quiet $(koha-list --enabled)
--- a/debian/scripts/koha-create
+++ a/debian/scripts/koha-create
@@ -752,6 +752,9 @@ then
# Start Zebra.
koha-zebra --start "$name"
+ # Start worker
+ koha-worker --start "$name"
+
if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
# Start Indexer daemon
koha-indexer --start "$name"
--- a/debian/scripts/koha-disable
+++ a/debian/scripts/koha-disable
@@ -72,6 +72,9 @@ do
if is_indexer_running $name; then
koha-indexer --stop $name
fi
+ if is_worker_running $name; then
+ koha-worker --stop $name
+ fi
elif [ "$RET" = 2 ]; then
warn "Error: Apache configuration file not present for instance $name."
else
--- a/debian/scripts/koha-functions.sh
+++ a/debian/scripts/koha-functions.sh
@@ -199,6 +199,20 @@ is_indexer_running()
fi
}
+is_worker_running()
+{
+ local instancename=$1
+
+ if daemon --name="$instancename-koha-worker" \
+ --pidfiles="/var/run/koha/$instancename/" \
+ --user="$instancename-koha.$instancename-koha" \
+ --running ; then
+ return 0
+ else
+ return 1
+ fi
+}
+
is_plack_enabled_opac()
{
local instancefile=$1
--- a/debian/scripts/koha-remove
+++ a/debian/scripts/koha-remove
@@ -81,6 +81,10 @@ eof
if is_indexer_running $name; then
koha-indexer --stop $name || /bin/true
fi
+ # Stop the worker daemon if needed
+ if is_worker_running $name; then
+ koha-worker --stop $name || /bin/true
+ fi
# Stop the Plack server if needed
if is_plack_running $name; then
koha-plack --stop $name || /bin/true
--- a/debian/scripts/koha-worker
+++ a/debian/scripts/koha-worker
@@ -0,0 +1,242 @@
+#!/bin/bash
+#
+# Copyright 2020 Koha Development team
+#
+# This program 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.
+#
+# This program 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 this program. If not, see .
+
+set -e
+
+. /lib/lsb/init-functions
+
+# Read configuration variable file if it is present
+[ -r /etc/default/koha-common ] && . /etc/default/koha-common
+
+# include helper functions
+if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
+ . "/usr/share/koha/bin/koha-functions.sh"
+else
+ echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
+ exit 1
+fi
+
+usage()
+{
+ local scriptname=$(basename $0)
+
+ cat <.
+
+use Modern::Perl;
+use JSON qw( encode_json decode_json );
+
+use Koha::BackgroundJob::BatchUpdateBiblio;
+use Koha::BackgroundJob;
+
+my $conn = Koha::BackgroundJob->connect;
+
+my $channel = $conn->open_channel();
+
+my $job_type = 'batch_biblio_record_modification';
+$channel->declare_queue(
+ queue => $job_type,
+ durable => 1,
+);
+
+$channel->qos(prefetch_count => 1,);
+
+$channel->consume(
+ on_consume => sub {
+ my $var = shift;
+ my $body = $var->{body}->{payload};
+ say " [x] Received $body";
+
+ my $args = decode_json( $body );
+
+ Koha::BackgroundJob::BatchUpdateBiblio->process($args, $channel);
+ say " [x] Done";
+ },
+ no_ack => 0,
+);
+
+warn "waiting forever";
+# Wait forever
+AnyEvent->condvar->recv;
--