06_update_everyday_feature.sh 3.0 KB

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