06_update_everyday_feature.sh 3.1 KB

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