06_update_everyday_feature.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/sh
  2. set -ex
  3. # 0 全局变量/参数
  4. today="$(date +%Y%m%d)"
  5. today_early_1="$(date -d '1 days ago' +%Y%m%d)"
  6. yesterday="$(date -d '1 days ago' +%Y%m%d)"
  7. HADOOP="/opt/apps/HADOOP-COMMON/hadoop-common-current/bin/hadoop"
  8. max_hour=11
  9. max_minute=00
  10. # 0 判断上游表是否生产完成,最长等待到12点
  11. source /root/anaconda3/bin/activate py37
  12. while true; do
  13. python_return_code=$(python utils.py --excute_program check_item_hive --partition ${today_early_1})
  14. if [ $python_return_code -eq 0 ]; then
  15. echo "Python程序返回0,退出循环。"
  16. break
  17. fi
  18. echo "Python程序返回非0值,等待五分钟后再次调用。"
  19. sleep 300
  20. current_hour=$(date +%H)
  21. current_minute=$(date +%M)
  22. if (( current_hour > max_hour || (current_hour == max_hour && current_minute >= max_minute) )); then
  23. echo "最长等待时间已到,失败:${current_hour}-${current_minute}"
  24. exit 1
  25. fi
  26. done
  27. conda deactivate
  28. # 1 item 生产数据
  29. /opt/apps/SPARK2/spark-2.4.8-hadoop3.2-1.0.8/bin/spark-class2 org.apache.spark.deploy.SparkSubmit \
  30. --class com.aliyun.odps.spark.examples.makedata.makedata_08_item2redis \
  31. --name makedata_08_item2redis_${today} \
  32. --master yarn --driver-memory 1G --executor-memory 1G --executor-cores 1 --num-executors 16 \
  33. /root/zhangbo/recommend-emr-dataprocess/target/spark-examples-1.0.0-SNAPSHOT-shaded.jar \
  34. date:${today_early_1} tablePart:32 expireDay:4 ifDebug:False \
  35. ifVideo:True ifWriteRedis:True savePathVideo:/dw/recommend/model/feature/video
  36. if [ $? -eq 1 ]; then
  37. echo "item写入redis执行失败"
  38. exit 1
  39. else
  40. echo "item写入redis执行成功"
  41. fi
  42. # 2 检查user上游表
  43. source /root/anaconda3/bin/activate py37
  44. while true; do
  45. python_return_code=$(python utils.py --excute_program check_user_hive --partition ${today_early_1})
  46. if [ $python_return_code -eq 0 ]; then
  47. echo "Python程序返回0,退出循环。"
  48. break
  49. fi
  50. echo "Python程序返回非0值,等待五分钟后再次调用。"
  51. sleep 300
  52. current_hour=$(date +%H)
  53. current_minute=$(date +%M)
  54. if (( current_hour > max_hour || (current_hour == max_hour && current_minute >= max_minute) )); then
  55. echo "最长等待时间已到,失败:${current_hour}-${current_minute}"
  56. exit 1
  57. fi
  58. done
  59. conda deactivate
  60. # 3 user 生产数据
  61. /opt/apps/SPARK2/spark-2.4.8-hadoop3.2-1.0.8/bin/spark-class2 org.apache.spark.deploy.SparkSubmit \
  62. --class com.aliyun.odps.spark.examples.makedata.makedata_09_user2redis \
  63. --name makedata_09_user2redis_${today} \
  64. --master yarn --driver-memory 1G --executor-memory 1G --executor-cores 1 --num-executors 32 \
  65. --conf spark.yarn.executor.memoryoverhead=128 \
  66. /root/zhangbo/recommend-emr-dataprocess/target/spark-examples-1.0.0-SNAPSHOT-shaded.jar \
  67. date:${today_early_1} tablePart:32 expireDay:3 ifDebug:False \
  68. ifUser:True ifDeleteRedisUser:False ifWriteRedisUser:True sampleRate:1.0 midDays:6 \
  69. savePathUser:/dw/recommend/model/feature/user/
  70. if [ $? -eq 1 ]; then
  71. echo "user写入redis执行失败"
  72. exit 1
  73. else
  74. echo "user写入redis执行成功"
  75. fi
  76. #nohup sh 06_update_everyday_feature.sh > p2.log 2>&1 &