#!/usr/bin/env bash
set -e
cd $(dirname $0)

if [ -f /etc/profile.d/ecb_athena.sh ]; then
  source /etc/profile.d/ecb_athena.sh;
fi

if [ -f /etc/profile.d/ecb_insights.sh ]; then
  source /etc/profile.d/ecb_insights.sh;
fi

pushd $PROJECT_ROOT
  source common/config/config.sh
popd

mkdir -p log
TIMESTAMP=$(date +"%Y_%m_%d")
LOG_NAME="datasink_worker_${TIMESTAMP}.log"
python datasink_worker.py -v --delayed-deletion-folder /tmp/delayed_datasink_deletions --log-file "/var/log/squirro/async_pipeline/${LOG_NAME}"

# clean old logs
find /var/log/squirro/async_pipeline/ -type f -mtime +7 -iname datasink_worker_\*.log -delete
