diff --git a/.env.example b/.env.example index 06bb568..f59065b 100644 --- a/.env.example +++ b/.env.example @@ -15,3 +15,4 @@ MANAGER_DATA=~/ MQ_HOST=kitodo-mq MQ_PORT=61616 +MQ_CLIENT_QUEUE=FinalizeTaskQueue diff --git a/Dockerfile b/Dockerfile index ace6c57..c0ae792 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,7 +20,7 @@ LABEL \ org.opencontainers.image.revision=$VCS_REF \ org.opencontainers.image.created=$BUILD_DATE -ARG KITODO_MQ_CLIENT_VERSION=0.2 +ARG KITODO_MQ_CLIENT_VERSION=0.3 ENV HOME=/ @@ -48,10 +48,13 @@ COPY kitodo-activemq-client-log4j2.properties /opt/kitodo-activemq-client/log4j2 ENV ACTIVEMQ_CLIENT_LOG4J2 /opt/kitodo-activemq-client/log4j2.properties # add ActiveMQ client library -ADD https://github.com/markusweigelt/kitodo-activemq-client/releases/download/${KITODO_MQ_CLIENT_VERSION}/kitodo-activemq-client-${KITODO_MQ_CLIENT_VERSION}.jar /opt/kitodo-activemq-client +ADD https://github.com/slub/kitodo-production-activemq/releases/download/${KITODO_MQ_CLIENT_VERSION}/kitodo-activemq-client-${KITODO_MQ_CLIENT_VERSION}.jar /opt/kitodo-activemq-client ENV ACTIVEMQ_CLIENT /opt/kitodo-activemq-client/kitodo-activemq-client-${KITODO_MQ_CLIENT_VERSION}.jar RUN chmod go+r $ACTIVEMQ_CLIENT +# configure ActiveMQ client queue +ENV ACTIVEMQ_CLIENT_QUEUE FinalizeTaskQueue + # workaround for OCR-D/core#983 RUN pip install ocrd # install mets-mods2tei and page-to-alto diff --git a/docker-compose.yml b/docker-compose.yml index d4f10bc..8ae206b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,6 +17,7 @@ services: - UMASK=${MANAGER_ENV_UMASK} - "CONTROLLER=${CONTROLLER_HOST}:${CONTROLLER_PORT_SSH}" - "ACTIVEMQ=${MQ_HOST}:${MQ_PORT}" + - ACTIVEMQ_CLIENT_QUEUE=${MQ_CLIENT_QUEUE} ports: - ${MANAGER_PORT_SSH}:22 diff --git a/ocrd_lib.sh b/ocrd_lib.sh index 713a93f..a6cf39d 100644 --- a/ocrd_lib.sh +++ b/ocrd_lib.sh @@ -8,6 +8,8 @@ TASK=$(basename $0) logerr() { logger -p user.info -t $TASK "terminating with error \$?=$? from ${BASH_COMMAND} on line $(caller)" + + kitodo_production_task_action_error_open } stopbg() { @@ -233,16 +235,71 @@ post_process_to_mets() { # perhaps if URL_PREFIX: mm-update -m "$METS_PATH" validate -u $URL_PREFIX } -close_task() { - if test -n "$ACTIVEMQ" -a -n "$ACTIVEMQ_CLIENT" -a -n "$TASK_ID" -a -n "$PROCESS_ID"; then - java -Dlog4j2.configurationFile=$ACTIVEMQ_CLIENT_LOG4J2 -jar "$ACTIVEMQ_CLIENT" "tcp://$ACTIVEMQ?closeAsync=false" "KitodoProduction.FinalizeStep.Queue" $TASK_ID $PROCESS_ID +kitodo_production_task_action() { + ACTION="" + MESSAGE="${2}" + case ${1} in + 1) + ACTION="COMMENT" + ;; + 2) + ACTION="ERROR_OPEN" + ;; + 3) + ACTION="ERROR_CLOSE" + ;; + 4) + ACTION="PROCESS" + ;; + 5) + ACTION="CLOSE" + ;; + *) + logger -p user.error -t $TASK "Unknown task action type" + ;; + esac + + if test -n "$ACTIVEMQ" -a "$ACTIVEMQ" != ":" -a -n "$TASK_ID" -a -n "$ACTION"; then + if test "$ACTIVEMQ_CLIENT_QUEUE" == "TaskActionQueue"; then + java -Dlog4j2.configurationFile=$ACTIVEMQ_CLIENT_LOG4J2 -jar "$ACTIVEMQ_CLIENT" "tcp://$ACTIVEMQ?closeAsync=false" "$ACTIVEMQ_CLIENT_QUEUE" $TASK_ID "$MESSAGE" "$ACTION" + elif test "$ACTION" == "CLOSE"; then + java -Dlog4j2.configurationFile=$ACTIVEMQ_CLIENT_LOG4J2 -jar "$ACTIVEMQ_CLIENT" "tcp://$ACTIVEMQ?closeAsync=false" "$ACTIVEMQ_CLIENT_QUEUE" $TASK_ID "$MESSAGE" + fi fi logret # communicate retval 0 } +kitodo_production_task_action_comment() { + if test -n "${1}"; then + kitodo_production_task_action 1 "${1}" + else + logger -p user.info -t $TASK "Could not send task info cause no message was specified" + fi +} + +kitodo_production_task_action_error_open() { + MESSAGE="${1:-Error occured during the OCR processing}" + kitodo_production_task_action 2 "$MESSAGE" +} + +kitodo_production_task_action_error_close() { + MESSAGE="${1:-OCR processing error has been fixed}" + kitodo_production_task_action 3 "$MESSAGE" +} + +kitodo_production_task_action_process() { + MESSAGE="${1:-OCR processing started}" + kitodo_production_task_action 4 "$MESSAGE" +} + +kitodo_production_task_action_close() { + MESSAGE="${1:-OCR processing completed}" + kitodo_production_task_action 5 "$MESSAGE" +} + # exit in async or sync mode close() { - if test -n "$ACTIVEMQ" -a -n "$ACTIVEMQ_CLIENT" -a -n "$TASK_ID" -a -n "$PROCESS_ID"; then + if test -n "$ACTIVEMQ" -a "$ACTIVEMQ" != ":" -a -n "$TASK_ID"; then logger -p user.info -t $TASK "ocr_exit in async mode - immediate termination of the script" # prevent any RETVAL from being written yet trap - EXIT diff --git a/process_images.sh b/process_images.sh index dd81067..48de135 100755 --- a/process_images.sh +++ b/process_images.sh @@ -53,6 +53,7 @@ ENVIRONMENT VARIABLES: CONTROLLER: host name and port of OCR-D Controller for processing ACTIVEMQ: URL of ActiveMQ server for result callback (optional) + ACTIVEMQ_QUEUE: Protocol type handling result callbacks. Choose between "FinalizeTaskQueue" (default) or "TaskActionQueue" (optional) ACTIVEMQ_CLIENT: path to ActiveMQ client library JAR file (optional) EOF exit;; @@ -88,6 +89,8 @@ init "$@" pre_sync_workdir + kitodo_production_task_action_process + ocrd_exec ocrd_import_workdir ocrd_validate_workflow ocrd_process_workflow post_sync_workdir @@ -96,7 +99,7 @@ init "$@" post_process_to_procdir - close_task + kitodo_production_task_action_close ) |& tee -a $WORKDIR/ocrd.log 2>&1 | logger -p user.info -t $TASK &>/dev/null & # without output redirect, ssh will not close the connection upon exit, cf. #9 diff --git a/process_mets.sh b/process_mets.sh index 965cc26..2056309 100755 --- a/process_mets.sh +++ b/process_mets.sh @@ -82,6 +82,8 @@ init "$@" pre_sync_workdir + kitodo_production_task_action_process + ocrd_exec ocrd_enter_workdir ocrd_validate_workflow ocrd_process_workflow post_sync_workdir @@ -90,7 +92,7 @@ init "$@" post_process_to_mets - close_task + kitodo_production_task_action_close ) |& tee -a $WORKDIR/ocrd.log 2>&1 | logger -p user.info -t $TASK &>/dev/null & # without output redirect, ssh will not close the connection upon exit, cf. #9