#!/bin/bash
. /pi/bin/inc/wait_funcs.sh
. /pi/bin/inc/matchers.sh
. /pi/bin/inc/docker_utils.sh

function start_inventory(){
	# mysqld: ready for connections.
	start_docker inventory "$msg_mysql"
}

scrapy="/Users/xiaofeiwu/miniconda3/envs/bigdata/bin/scrapy"

# startup 
if [ $# -lt 1 ]; then	
	echo "available opts: all, zk, storm, repl, ..."
else
	CMD=$1
	case "$CMD" in
	"redis")
		start_docker redis "$msg_redis"
		;;
	"inventory")
		start_inventory
		;;
	"cr")
	    if [ $# -lt 2 ]; then
	        echo 'absent lang, exit.'
	        exit
	    fi
	    lang=$2
	    $scrapy crawl content -o content_${lang}.json -a tag=${lang}  -a limit=10
	    ;;
	"cr100")
	    if [ $# -lt 2 ]; then
	        echo 'absent lang, exit.'
	        exit
	    fi
	    lang=$2
	    $scrapy crawl content -o all_${lang}.json -a tag=${lang}  -a limit=100
	    ;;
	*)
		# default proc
		handle_cmd ${@:1}
		;;
	esac
fi

