Skip to content

Commit

Permalink
improve names of webhook actions
Browse files Browse the repository at this point in the history
  • Loading branch information
markusweigelt committed Mar 1, 2024
1 parent 55e3144 commit b1e3d26
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
28 changes: 10 additions & 18 deletions ocrd_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -263,22 +263,14 @@ close() {
}

webhook_send() {
EVENT=""
EVENT="${1}"
MESSAGE="${2}"
JOBCOMPLETE=0
case ${1} in
1)
EVENT="INFO"
;;
2)
EVENT="ERROR"
JOBCOMPLETE=1
;;
3)
EVENT="STARTED"

case "$EVENT" in
INFO|STARTED)
JOBCOMPLETE=0
;;
4)
EVENT="COMPLETED"
ERROR|COMPLETED)
JOBCOMPLETE=1
;;
*)
Expand All @@ -302,23 +294,23 @@ webhook_request() {

webhook_send_info() {
if test -n "${1}"; then
webhook_send 1 "${1}"
webhook_send "INFO" "${1}"
else
logger -p user.info -t $TASK "Could not send webhook event info cause no message was specified"
fi
}

webhook_send_error() {
MESSAGE="${1:-Error occured during the OCR processing}"
webhook_send 2 "$MESSAGE"
webhook_send "ERROR" "$MESSAGE"
}

webhook_send_started() {
MESSAGE="${1:-OCR processing started}"
webhook_send 3 "$MESSAGE"
webhook_send "STARTED" "$MESSAGE"
}

webhook_send_completed() {
MESSAGE="${1:-OCR processing completed}"
webhook_send 4 "$MESSAGE"
webhook_send "COMPLETED" "$MESSAGE"
}
15 changes: 8 additions & 7 deletions process_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,25 @@ WEBHOOK_KEY_DATA=$TASK_ID
# Overwrite webhook_request "$WEBHOOK_RECEIVER_URL" "$WEBHOOK_KEY_DATA" "$EVENT" "$MESSAGE"
webhook_request() {
ACTION=""
case ${3} in
"INFO")

case "$3" in
INFO)
ACTION="COMMENT"
;;
"ERROR")
ERROR)
ACTION="ERROR_OPEN"
;;
"STARTED")
STARTED)
ACTION="PROCESS"
;;
"COMPLETED")
COMPLETED)
ACTION="CLOSE"
;;
;;
*)
logger -p user.error -t $TASK "Unknown task action type"
;;
esac

if test -n "$ACTION"; then
if test "$ACTIVEMQ_QUEUE" == "TaskActionQueue"; then
java -Dlog4j2.configurationFile=$KITODO_PRODUCTION_ACTIVEMQ_CLIENT_LOG4J2 -jar "$KITODO_PRODUCTION_ACTIVEMQ_CLIENT" "${1}" "$ACTIVEMQ_QUEUE" ${2} "${4}" "$ACTION"
Expand Down

0 comments on commit b1e3d26

Please sign in to comment.