之前的文章依赖是1对1或1多对的,但每个任务的前置任务都只有1个。
本文的核心在于一个任务依赖于多个任务的执行完成,如上图所示,这个任务就是fact,只有new和dviduser两个任务都完成的情况下,fact才能继续执行。
init_pipe.sh
# 初始化file descriptor init_pipe(){ [ -e /tmp/fd1001 ] || mkfifo /tmp/fd1001 exec 1001<>/tmp/fd1001 rm -rf /tmp/fd1001 [ -e /tmp/fd1002 ] || mkfifo /tmp/fd1002 exec 1002<>/tmp/fd1002 rm -rf /tmp/fd1002 [ -e /tmp/fd1003 ] || mkfifo /tmp/fd1003 exec 1003<>/tmp/fd1003 rm -rf /tmp/fd1003 [ -e /tmp/fd1004 ] || mkfifo /tmp/fd1004 exec 1004<>/tmp/fd1004 rm -rf /tmp/fd1004 [ -e /tmp/fd1005 ] || mkfifo /tmp/fd1005 exec 1005<>/tmp/fd1005 rm -rf /tmp/fd1005 [ -e /tmp/fd1006 ] || mkfifo /tmp/fd1006 exec 1006<>/tmp/fd1006 rm -rf /tmp/fd1006 [ -e /tmp/fd1007 ] || mkfifo /tmp/fd1007 exec 1007<>/tmp/fd1007 rm -rf /tmp/fd1007 } destroy_pipe(){ exec 1001<&- exec 1001>&- exec 1002<&- exec 1002>&- exec 1003<&- exec 1003>&- exec 1004<&- exec 1004>&- exec 1005>&- exec 1005<&- exec 1006<&- exec 1006>&- exec 1007>&- exec 1007<&- }
work.sh
# 初始化file descriptor . init_pipe.sh . sql_lib.sh ################################################################ newFun(){ start_day=$1 end_day=$2 while [ ${start_day} -le ${end_day} ] do day=`date +"%Y-%m-%d" -d "${start_day}"` echo "${new_sql//_day_/${day}}" hive -e "${new_sql//_day_/${day}}" echo ${start_day} >& 1001 start_day=`date +"%Y%m%d" -d "${start_day} 1 days" ` done } ################################################################ factFun(){ start_day=$1 end_day=$2 while [ ${start_day} -le ${end_day} ] do day=`date +"%Y-%m-%d" -d "${start_day}"` read -u 1001 j read -u 1007 k if [ ${start_day} -le $j -a ${start_day} -le $k ];then echo "${fact_sql//_day_/${day}}" hive -e "${fact_sql//_day_/${day}}" echo ${start_day}>& 1002 echo ${start_day}>& 1003 echo ${start_day}>& 1004 fi start_day=`date +"%Y%m%d" -d "${start_day} 1 days" ` done } ################################################################ dvidUserIdFun(){ start_day=$1 end_day=$2 while [ ${start_day} -le ${end_day} ] do day=`date +"%Y-%m-%d" -d "${start_day}"` echo "${dvid_user_id_sql//_day_/${day}}" hive -e "${dvid_user_id_sql//_day_/${day}}" echo ${start_day}>& 1005 echo ${start_day}>& 1006 echo ${start_day}>& 1007 start_day=`date +"%Y%m%d" -d "${start_day} 1 days" ` done } init_pipe newFun "${start}" "${end}" & factFun "${start}" "${end}" & dvidUserIdFun "${start}" "${end}" & wait destroy_pipe