06_update_everyday_feature.sh 3.1 KB

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