Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 75 additions & 67 deletions .circleci/cron.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,75 +4,83 @@
# a non-zero exit code
set -e

echo "Logging into cloud.gov"
# Set # of failures to 0
F=0

function run_production_tasks() {
# === PRODUCTION environment ===================================================
echo "Running tasks in Production..."

PROD_TASK="cf run-task touchpoints-production-sidekiq-worker --wait -c"
# Users
$PROD_TASK "rake scheduled_jobs:send_one_week_until_inactivation_warning" || F=$((F+=1))
$PROD_TASK "rake scheduled_jobs:send_two_weeks_until_inactivation_warning" || F=$((F+=1))
$PROD_TASK "rake scheduled_jobs:deactivate_inactive_users" || F=$((F+=1))

# Forms
# $PROD_TASK "rake scheduled_jobs:send_daily_notifications" || F=$((F+=1))
# $PROD_TASK "rake scheduled_jobs:send_weekly_notifications" || F=$((F+=1))
# $PROD_TASK "rake scheduled_jobs:check_expiring_forms" || F=$((F+=1))
# $PROD_TASK "rake scheduled_jobs:archive_forms" || F=$((F+=1))
$PROD_TASK "rake scheduled_jobs:notify_form_managers_of_inactive_forms" || F=$((F+=1))
# $PROD_TASK "rake scheduled_jobs:delete_submissions_trash" || F=$((F+=1))
echo "Production tasks have completed."
}


function run_staging_tasks() {
# === STAGING environment ======================================================
echo "Running tasks in Staging..."

STAGING_TASK="cf run-task touchpoints-staging-sidekiq-worker --wait -c"

# Users
$STAGING_TASK "rake scheduled_jobs:send_one_week_until_inactivation_warning" || F=$((F+=1))
$STAGING_TASK "rake scheduled_jobs:send_two_weeks_until_inactivation_warning" || F=$((F+=1))
$STAGING_TASK "rake scheduled_jobs:deactivate_inactive_users" || F=$((F+=1))

# Forms
$STAGING_TASK "rake scheduled_jobs:send_daily_notifications" || F=$((F+=1))
$STAGING_TASK "rake scheduled_jobs:send_weekly_notifications" || F=$((F+=1))
$STAGING_TASK "rake scheduled_jobs:check_expiring_forms" || F=$((F+=1))
$STAGING_TASK "rake scheduled_jobs:archive_forms" || F=$((F+=1))
$STAGING_TASK "rake scheduled_jobs:notify_form_managers_of_inactive_forms" || F=$((F+=1))
# $STAGING_TASK "rake scheduled_jobs:delete_submissions_trash" || F=$((F+=1))

echo "Staging tasks have completed."
}

function run_demo_tasks() {
# === DEMO environment =========================================================
echo "Running tasks in Demo..."
DEMO_TASK="cf run-task touchpoints-demo-sidekiq-worker --wait -c"

# Users
$DEMO_TASK "rake scheduled_jobs:send_one_week_until_inactivation_warning" || F=$((F+=1))
$DEMO_TASK "rake scheduled_jobs:send_two_weeks_until_inactivation_warning" || F=$((F+=1))
$DEMO_TASK "rake scheduled_jobs:deactivate_inactive_users" || F=$((F+=1))

# Forms
$DEMO_TASK "rake scheduled_jobs:send_daily_notifications" || F=$((F+=1))
$DEMO_TASK "rake scheduled_jobs:send_weekly_notifications" || F=$((F+=1))
$DEMO_TASK "rake scheduled_jobs:check_expiring_forms" || F=$((F+=1))
$DEMO_TASK "rake scheduled_jobs:archive_forms" || F=$((F+=1))
$DEMO_TASK "rake scheduled_jobs:notify_form_managers_of_inactive_forms" || F=$((F+=1))
# $DEMO_TASK "rake scheduled_jobs:delete_submissions_trash" || F=$((F+=1))

echo "Demo tasks have completed."
}

echo "Logging into cloud.gov non-prod"
cf login -a $CF_API_ENDPOINT -u $CF_USERNAME -p $CF_PASSWORD -o $CF_ORG -s $CF_SPACE

#
# === STAGING environment ======================================================
#

echo "Running tasks in Staging..."

# Users
cf run-task touchpoints-staging-sidekiq-worker -c "rake scheduled_jobs:send_one_week_until_inactivation_warning"
cf run-task touchpoints-staging-sidekiq-worker -c "rake scheduled_jobs:send_two_weeks_until_inactivation_warning"
cf run-task touchpoints-staging-sidekiq-worker -c "rake scheduled_jobs:deactivate_inactive_users"

# Forms
cf run-task touchpoints-staging-sidekiq-worker -c "rake scheduled_jobs:send_daily_notifications"
cf run-task touchpoints-staging-sidekiq-worker -c "rake scheduled_jobs:send_weekly_notifications"
cf run-task touchpoints-staging-sidekiq-worker -c "rake scheduled_jobs:check_expiring_forms"
cf run-task touchpoints-staging-sidekiq-worker -c "rake scheduled_jobs:archive_forms"
cf run-task touchpoints-staging-sidekiq-worker -c "rake scheduled_jobs:notify_form_managers_of_inactive_forms"
# cf run-task touchpoints-staging-sidekiq-worker -c "rake scheduled_jobs:delete_submissions_trash"

echo "Staging tasks have completed."

#
# === DEMO environment =========================================================
#

echo "Running tasks in Demo..."

# Users
cf run-task touchpoints-demo-sidekiq-worker -c "rake scheduled_jobs:send_one_week_until_inactivation_warning"
cf run-task touchpoints-demo-sidekiq-worker -c "rake scheduled_jobs:send_two_weeks_until_inactivation_warning"
cf run-task touchpoints-demo-sidekiq-worker -c "rake scheduled_jobs:deactivate_inactive_users"

# Forms
cf run-task touchpoints-demo-sidekiq-worker -c "rake scheduled_jobs:send_daily_notifications"
cf run-task touchpoints-demo-sidekiq-worker -c "rake scheduled_jobs:send_weekly_notifications"
cf run-task touchpoints-demo-sidekiq-worker -c "rake scheduled_jobs:check_expiring_forms"
cf run-task touchpoints-demo-sidekiq-worker -c "rake scheduled_jobs:archive_forms"
cf run-task touchpoints-demo-sidekiq-worker -c "rake scheduled_jobs:notify_form_managers_of_inactive_forms"
# cf run-task touchpoints-demo-sidekiq-worker -c "rake scheduled_jobs:delete_submissions_trash"

echo "Demo tasks have completed."

run_staging_tasks
run_demo_tasks
cf logout

#
# === PRODUCTION environment ===================================================
#

echo "Logging into cloud.gov"
echo "Logging into cloud.gov production environment"
cf login -a $CF_API_ENDPOINT -u $CF_PRODUCTION_SPACE_DEPLOYER_USERNAME -p $CF_PRODUCTION_SPACE_DEPLOYER_PASSWORD -o $CF_ORG -s prod

echo "Running tasks in Production..."

# Users
cf run-task touchpoints-production-sidekiq-worker -c "rake scheduled_jobs:send_one_week_until_inactivation_warning"
cf run-task touchpoints-production-sidekiq-worker -c "rake scheduled_jobs:send_two_weeks_until_inactivation_warning"
cf run-task touchpoints-production-sidekiq-worker -c "rake scheduled_jobs:deactivate_inactive_users"

# Forms
# cf run-task touchpoints-production-sidekiq-worker -c "rake scheduled_jobs:send_daily_notifications"
# cf run-task touchpoints-production-sidekiq-worker -c "rake scheduled_jobs:send_weekly_notifications"
# cf run-task touchpoints-production-sidekiq-worker -c "rake scheduled_jobs:check_expiring_forms"
# cf run-task touchpoints-production-sidekiq-worker -c "rake scheduled_jobs:archive_forms"
cf run-task touchpoints-production-sidekiq-worker -c "rake scheduled_jobs:notify_form_managers_of_inactive_forms"
# cf run-task touchpoints-production-sidekiq-worker -c "rake scheduled_jobs:delete_submissions_trash"

echo "Production tasks have completed."

run_production_tasks
cf logout

echo "$0 exiting with failure count: $F"
exit $F