wait_activities 1.41 KB
Newer Older
1
#!/bin/sh
2
set -e
3 4 5 6
# Small wait script based on watch_activities scripts.

# The goal is keep running until the activities.

7
show_help()
8
{
9 10
  script_name=`basename "$0"`
  echo "
11 12 13 14 15 16 17 18 19 20
  Usage:
    $script_name <mysql_opt> [interval seconds] [timeout in seconds]
  Interval is default 5.
  Timeout default is 600 seconds.
  mysql_opt are default mysql command line options.
  Put them in quotes if more than one option is passed.

  Typical usage:
    $script_name erp5
    $script_name \"-h remotehost -u user erp5remote\" 3
21
"
22 23 24 25 26
}

MYSQL_OPT=$1
INTERVAL=$2
TIMEOUT=$3
27

28
[ "$MYSQL" ] || MYSQL=mysql
29

30
[ "$MYSQL_OPT" ] || {
31 32
  show_help
  exit 1
33
}
34

35 36
[ "$INTERVAL" ] || INTERVAL=5
[ "$TIMEOUT"  ] || TIMEOUT=600
37 38 39 40 41

TIME=0

while true
do
42 43 44
    MESSAGE_VALUE=`echo "SELECT count(*) AS message_count FROM message;" | $MYSQL $MYSQL_OPT | grep -v message`
    MESSAGE_QUEUE_VALUE=`echo "SELECT count(*) AS message_count FROM message_queue;" | $MYSQL $MYSQL_OPT | grep -v message`
    [ "$MESSAGE_VALUE" = 0 ] && [ "$MESSAGE_QUEUE_VALUE" = 0 ] && break
45
    sleep $INTERVAL;
46
    TIME=`expr $TIME + $INTERVAL`
47 48
    if [ $TIME -gt $TIMEOUT ]
    then
49
        echo "Messages"
50
        echo "SELECT path, processing_node, method_id AS message_count FROM message;" | $MYSQL $MYSQL_OPT
51
        echo "Messages Queue"
52
        echo "SELECT path, processing_node, method_id AS message_count FROM message_queue;" | $MYSQL $MYSQL_OPT
53 54 55 56
        echo "Timeout"
        exit 1
    fi
done