#!/bin/bash

set -xe

if [ "$RELOAD" = 'true' ] ; then
  reload_arg='True'
else
  reload_arg='False'
fi

if [ $REPORT = "ALL" ] ; then
  reports="adsupported prime unlimited"
  delay="5m"
else
  reports=$REPORT
  delay="0"
fi

for report in $reports ; do
  context="\"report_name\": \"$report\", \"licensor\": \"$LICENSOR\", \"reload\": \"'$reload_arg'\""
  if [ ! -z "$COUNTRIES" ] ; then
    context="${context}, \"countries\":\"$COUNTRIES\" "
  fi

  python feed_ingestion/bin/exec_flows.py amazon_music --skip $SKIP --days $DAYS \
    --context "{${context}}" \
    --check-status --max_concurrent_flows 8

  sleep $delay # to prevent processing files in the same time due to space limitations
done

