24_supplementary_data.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/sh
  2. set -x
  3. # 广告补数据脚本,修改{today_early_1}补单天的数据
  4. export PATH=$SPARK_HOME/bin:$PATH
  5. export HADOOP_CONF_DIR=/etc/taihao-apps/hadoop-conf
  6. export JAVA_HOME=/usr/lib/jvm/java-1.8.0
  7. sh_path=$(cd $(dirname $0); pwd)
  8. source ${sh_path}/00_common.sh
  9. source /root/anaconda3/bin/activate py37
  10. # 全局常量
  11. LOG_PREFIX=广告模型训练任务
  12. HADOOP=/opt/apps/HADOOP-COMMON/hadoop-common-current/bin/hadoop
  13. TRAIN_PATH=/dw/recommend/model/31_ad_sample_data_v4
  14. BUCKET_FEATURE_PATH=/dw/recommend/model/33_ad_train_data_v4
  15. TABLE=alg_recsys_ad_sample_all
  16. # 任务开始时间
  17. start_time=$(date +%s)
  18. # 前一天
  19. today_early_1="$(date -d '1 days ago' +%Y%m%d)"
  20. # 校验命令的退出码
  21. check_run_status() {
  22. local status=$1
  23. local step_start_time=$2
  24. local step_name=$3
  25. local msg=$4
  26. local step_end_time=$(date +%s)
  27. local step_elapsed=$((${step_end_time} - ${step_start_time}))
  28. if [ ${status} -ne 0 ]; then
  29. echo "${LOG_PREFIX} -- ${step_name}失败: 耗时 ${step_elapsed}"
  30. local elapsed=$((${step_end_time} - ${start_time}))
  31. /root/anaconda3/bin/python ${sh_path}/ad_monitor_util.py --level error --msg "${msg}" --start "${start_time}" --elapsed "${elapsed}" --top10 "${top10_msg}"
  32. exit 1
  33. else
  34. echo "${LOG_PREFIX} -- ${step_name}成功: 耗时 ${step_elapsed}"
  35. fi
  36. }
  37. # 校验大数据任务是否执行完成
  38. check_ad_hive() {
  39. local step_start_time=$(date +%s)
  40. local max_hour=05
  41. local max_minute=30
  42. local elapsed=0
  43. while true; do
  44. local python_return_code=$(python ${sh_path}/ad_utils.py --excute_program check_ad_origin_hive --partition ${today_early_1} --hh 23)
  45. elapsed=$(($(date +%s) - ${step_start_time}))
  46. if [ "${python_return_code}" -eq 0 ]; then
  47. break
  48. fi
  49. echo "Python程序返回非0值,等待五分钟后再次调用。"
  50. sleep 300
  51. local current_hour=$(date +%H)
  52. local current_minute=$(date +%M)
  53. if (( ${current_hour} > ${max_hour} || ( ${current_hour} == ${max_hour} && ${current_minute} >= ${max_minute} ) )); then
  54. local msg="大数据数据生产校验失败, 分区: ${today_early_1}"
  55. echo -e "${LOG_PREFIX} -- 大数据数据生产校验 -- ${msg}: 耗时 ${elapsed}"
  56. /root/anaconda3/bin/python ${sh_path}/ad_monitor_util.py --level error --msg "${msg}" --start "${start_time}" --elapsed "${elapsed}"
  57. exit 1
  58. fi
  59. done
  60. echo "${LOG_PREFIX} -- 大数据数据生产校验 -- 大数据数据生产校验通过: 耗时 $elapsed"
  61. }
  62. origin_data() {
  63. (
  64. source ${sh_path}/25_xgb_make_data_origin_bucket.sh
  65. make_origin_data
  66. )
  67. }
  68. bucket_feature() {
  69. (
  70. source ${sh_path}/25_xgb_make_data_origin_bucket.sh
  71. make_bucket_feature
  72. )
  73. }
  74. # 主方法
  75. main() {
  76. check_ad_hive
  77. origin_data
  78. bucket_feature
  79. }
  80. main