
# Edit this file to introduce tasks to be run by cron.
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# 
# m h  dom mon dow   command


USERNAME=prod
SHELL=/bin/bash
LOGDIR=/data/log
REPORTS=/home/prod/gqr/model/model/utils/reports/
UTILS=/home/prod/gqr/model/model/utils
REPORTING=/home/prod/gqr/model/model/reporting

MODEL_ROOT=/home/prod/gqr/model/
MODEL_BRANCH=model
PYTHONE=/home/prod/miniconda3/envs/env1/bin/python
DATAPROC=/home/prod/gqr/DataProc/DataProc
GQR_ENV=/home/prod/gqr/extra/env
PYTHONPATH=/home/prod/gqr/DataProc

######################## START AWS DELETION JOBS #########
0 2 * * * ${PYTHONE} ${GQR_ENV}/prune_aws_backups_by_plan.py --backup-plan-name "prod-EGProd1-backup" --region us-west-2 --no-dry-run 2>&1
0 2 * * * ${PYTHONE} ${GQR_ENV}/prune_aws_backups_by_plan.py --backup-plan-name "refinitiv-server-bkup" --region us-west-2 --no-dry-run 2>&1
0 2 * * * ${PYTHONE} ${GQR_ENV}/prune_aws_backups_by_plan.py --backup-plan-name "gqr-sql-server-bkup" --region us-west-2 --no-dry-run 2>&1
0 2 * * * ${PYTHONE} ${GQR_ENV}/prune_aws_backups_by_plan.py --backup-plan-name "prod-server1-bkup" --region us-west-2 --no-dry-run 2>&1
######################## END AWS DELETION JOBS #########

######################## START CRON JOBS MOVED FROM OLD PROD #########

15 8 15 6,12 *  ${PYTHONE} ${DATAPROC}/QAD/Ds2Views.py             > ${LOGDIR}/QAD.Ds2Views.crontab  2>&1
16 8 15 6,12 *  ${PYTHONE} ${DATAPROC}/QAD/RKDViews.py             > ${LOGDIR}/QAD.RKDViews.crontab  2>&1
17 8 15 6,12 *  ${PYTHONE} ${DATAPROC}/QAD/TREViews.py             > ${LOGDIR}/QAD.TREViews.crontab  2>&1

00,30 14,15 * * * ${PYTHONE} ${DATAPROC}/PBData/ShortAvailability_GS.py  > ${LOGDIR}/PBData.ShortAvailability_GS.crontab  2>&1

13 19 * * *  ${PYTHONE} ${DATAPROC}/PBData/ShortAvailability_GS.py   > ${LOGDIR}/PBData.ShortAvailability_GS.crontab  2>&1

######################## END CRON JOBS MOVED FROM OLD PROD #########

# Run the GS Stability files daily at this time. Since we are not sure when GS writes today's file we will get files from 2 days ago till today. We need files before the optimizer runs, Since they send files many times during the day we will 
# run this job twice once just before the optimizer starts and one when we receive the actual GS_China_Connect_IN files

0 2 * * * source /home/prod/gqr/live_model.env && ${PYTHONE} ${DATAPROC}/PBData/process_gs_stability_files.py --start_date $(date -d '2 days ago' +\%Y-\%m-\%d) --end_date $(date +\%Y-\%m-\%d)
0 14 * * * source /home/prod/gqr/live_model.env && ${PYTHONE} ${DATAPROC}/PBData/process_gs_stability_files.py --start_date $(date -d '2 days ago' +\%Y-\%m-\%d) --end_date $(date +\%Y-\%m-\%d)

#email if prices are late
30 10 * * 1-5 bash -c 'OUT=$(${PYTHONE} -c "from model.utils.make_alpha import emailPriceStatus; emailPriceStatus('\''20260205'\'')" 2>&1 | tee /tmp/priceframe_run.log | grep -F "price arrived=False"); if [ -n "$OUT" ]; then aws ses send-email --from "ap-production@greenwichquantitative.com" --destination "ToAddresses=rdarak@greenwichquantitative.com" --message "Subject={Data=Missing Prices - Call Refinitiv},Body={Text={Data=$OUT}}" --region us-west-2; fi'

### HK IPO scraper
00 3 * * * source /home/prod/gqr/live_model.env && ${PYTHONE} ${REPORTING}/hkex_ipo_scraper.py 2>&1

### update HK lot size from file downloaded from HK exchange website
10 3 * * * /bin/bash -c 'source /home/prod/gqr/live_model.env && ${PYTHONE} ${DATAPROC}/Bloomberg/UpdateHKLotSize.py' > /data/log/UpdateHKLotSize.log 2>&1

### Run GCAT YTD position research and PNL
#* * * * 1-5 /bin/bash -c 'source /home/prod/gqr/live_model.env && ${PYTHONE} /usr/local/bin/gcat position "$(date +\%Y)0101:$(date +\%Y\%m\%d)" --calc_pnl year,month,day --silent' > /data/log/gcat_position_pnl.log 2>&1
30 15 * * 1-5 /bin/bash -c 'source /home/prod/gqr/live_model.env && ${PYTHONE} /usr/local/bin/gcat position "$(date +\%Y)0101:$(date +\%Y\%m\%d)" --calc_pnl year,month,day --silent' > /data/log/gcat_position_pnl.log 2>&1


5 12 * * 4 /usr/bin/crontab -l > /home/prod/crontab.out

