Skip to content

Commit

Permalink
Separating out the text logging so that the cron job can run from non…
Browse files Browse the repository at this point in the history
…-log directory.
  • Loading branch information
ntai-arxiv committed Oct 3, 2023
1 parent 6aa5de7 commit 326b783
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions script/sync_prod_to_gcp/sync_published.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
#!/bin/bash
TEXT_LOG_DIR=/opt_arxiv/e-prints/dissemination/sync_prod_to_gcp
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "$SCRIPT_DIR"
if [ ! -d sync.venv ] ; then
make
fi

echo $1

# Is this a test/
if [ "$1" = "YES_THIS_IS_A_TEST" ]
then
shift
TESTING_ARGS="-v -d --test"
fi


# if running between 8pm and midnight
DATE=`date +%y%m%d --date='12:00 tomorrow'`
if [ ! -z $1 ]
Expand All @@ -33,43 +31,42 @@ then
fi

JSON_LOG_DIR=/opt_arxiv/e-prints/logs/sync
mkdir -p /opt_arxiv/e-prints/logs/sync
mkdir -p $JSON_LOG_DIR

. sync.venv/bin/activate
export GOOGLE_APPLICATION_CREDENTIALS=~/arxiv-production-cred.json
python sync_published_to_gcp.py $TESTING_ARGS --json-log-dir $JSON_LOG_DIR /data/new/logs/publish_$DATE.log > sync_published_$DATE.report 2> sync_published_$DATE.err
python sync_published_to_gcp.py $TESTING_ARGS --json-log-dir $JSON_LOG_DIR /data/new/logs/publish_$DATE.log > $TEXT_LOG_DIR/sync_published_$DATE.report 2> $TEXT_LOG_DIR/sync_published_$DATE.err
deactivate

if [ ! -z "$TESTING_ARGS" ]; then
exit 0
fi

if [ -s sync_published_$DATE.report ]
if [ -s $TEXT_LOG_DIR/sync_published_$DATE.report ]
then
if /bin/gsutil -q -h "Content-Type:text/plain" cp \
sync_published_$DATE.report gs://legacy_support/sync_published/$DATE.report ;
$TEXT_LOG_DIR/sync_published_$DATE.report gs://legacy_support/sync_published/$DATE.report ;
then
rm sync_published_$DATE.report
rm -f $TEXT_LOG_DIR/sync_published_$DATE.report
else
echo "Could not save report to GS! leaving on disk"
fi
else
echo "sync_published_to_gcp upload report was zero size" >> sync_published_$DATE.err
echo "sync_published_to_gcp upload report was zero size" >> $TEXT_LOG_DIR/sync_published_$DATE.err
fi

if [ -s sync_published_$DATE.err ]
if [ -s $TEXT_LOG_DIR/sync_published_$DATE.err ]
then
head -n 100 sync_published_$DATE.err
head -n 100 $TEXT_LOG_DIR/sync_published_$DATE.err

if /bin/gsutil -q -h "Content-Type:text/plain" cp \
sync_published_$DATE.err gs://legacy_support/sync_published/$DATE.err ;
$TEXT_LOG_DIR/sync_published_$DATE.err gs://legacy_support/sync_published/$DATE.err ;
then
printf "\n\nError log saved at gs://legacy_support/sync_published/$DATE.err\n"
rm sync_published_$DATE.err
rm $TEXT_LOG_DIR/sync_published_$DATE.err
else
echo "Could not save error report! leaving on disk"
fi

exit 1
fi

0 comments on commit 326b783

Please sign in to comment.