Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 8 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,14 @@ jobs:
sudo apt-get install -y cf8-cli
cf -v
- run:
name: Run CRON tasks
command: ./.circleci/cron.sh
name: Run CRON tasks for production
command: ./.circleci/cron.sh production
- run:
name: Run CRON tasks for demo
command: ./.circleci/cron.sh demo
- run:
name: Run CRON tasks for staging
command: ./.circleci/cron.sh staging

workflows:
daily_workflow:
Expand Down
107 changes: 66 additions & 41 deletions .circleci/cron.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,28 @@ set -e
# Set # of failures to 0
F=0

function run_scheduled_job() {
local app=$1
local job=$2
cf run-task $app --wait --name $job -c "rake scheduled_jobs:$job" || F=$((F+=1))
}

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))
run_scheduled_job "touchpoints-production-sidekiq-worker" "send_one_week_until_inactivation_warning"
run_scheduled_job "touchpoints-production-sidekiq-worker" "send_two_weeks_until_inactivation_warning"
run_scheduled_job "touchpoints-production-sidekiq-worker" "deactivate_inactive_users"

# 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))
# run_task "touchpoints-production-sidekiq-worker" "rake scheduled_jobs:send_daily_notifications"
# run_task "touchpoints-production-sidekiq-worker" "rake scheduled_jobs:send_weekly_notifications"
# run_task "touchpoints-production-sidekiq-worker" "rake scheduled_jobs:check_expiring_forms"
# run_task "touchpoints-production-sidekiq-worker" "rake scheduled_jobs:archive_forms"
run_scheduled_job "touchpoints-production-sidekiq-worker" "notify_form_managers_of_inactive_forms"
# run_task "touchpoints-production-sidekiq-worker" "rake scheduled_jobs:delete_submissions_trash"
echo "Production tasks have completed."
}

Expand All @@ -32,55 +37,75 @@ 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))
run_scheduled_job "touchpoints-staging-sidekiq-worker" "send_one_week_until_inactivation_warning"
run_scheduled_job "touchpoints-staging-sidekiq-worker" "send_two_weeks_until_inactivation_warning"
run_scheduled_job "touchpoints-staging-sidekiq-worker" "deactivate_inactive_users"

# 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))
run_scheduled_job "touchpoints-staging-sidekiq-worker" "send_daily_notifications"
run_scheduled_job "touchpoints-staging-sidekiq-worker" "send_weekly_notifications"
run_scheduled_job "touchpoints-staging-sidekiq-worker" "check_expiring_forms"
run_scheduled_job "touchpoints-staging-sidekiq-worker" "archive_forms"
run_scheduled_job "touchpoints-staging-sidekiq-worker" "notify_form_managers_of_inactive_forms"
# run_task "touchpoints-staging-sidekiq-worker" "rake scheduled_jobs:delete_submissions_trash"

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))
run_scheduled_job "touchpoints-demo-sidekiq-worker" "send_one_week_until_inactivation_warning"
run_scheduled_job "touchpoints-demo-sidekiq-worker" "send_two_weeks_until_inactivation_warning"
run_scheduled_job "touchpoints-demo-sidekiq-worker" "deactivate_inactive_users"

# 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))
run_scheduled_job "touchpoints-demo-sidekiq-worker" "send_daily_notifications"
run_scheduled_job "touchpoints-demo-sidekiq-worker" "send_weekly_notifications"
run_scheduled_job "touchpoints-demo-sidekiq-worker" "check_expiring_forms"
run_scheduled_job "touchpoints-demo-sidekiq-worker" "archive_forms"
run_scheduled_job "touchpoints-demo-sidekiq-worker" "notify_form_managers_of_inactive_forms"
# run_task "touchpoints-demo-sidekiq-worker" "rake scheduled_jobs:delete_submissions_trash"

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
run_staging_tasks
run_demo_tasks
cf logout

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
run_production_tasks
cf logout
TARGET_ENV="${1:-}"

if [ -z "$TARGET_ENV" ]; then
echo "Usage: ./.circleci/cron.sh <production|demo|staging>"
exit 1
fi


case "$TARGET_ENV" in
production)
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
run_production_tasks
cf logout
;;
demo)
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
run_demo_tasks
cf logout
;;
staging)
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
run_staging_tasks
cf logout
;;
*)
echo "Unknown environment: $TARGET_ENV"
echo "Usage: ./.circleci/cron.sh <production|demo|staging>"
exit 1
;;
esac

echo "$0 exiting with failure count: $F"
exit $F
24 changes: 12 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ GEM
acts-as-taggable-on (13.0.0)
activerecord (>= 7.1, < 8.2)
zeitwerk (>= 2.4, < 3.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
addressable (2.9.0)
public_suffix (>= 2.0.2, < 8.0)
aes_key_wrap (1.1.0)
ast (2.4.3)
aws-actionmailer-ses (1.0.0)
Expand Down Expand Up @@ -158,7 +158,7 @@ GEM
ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1)
base64 (0.3.0)
bcrypt (3.1.20)
bcrypt (3.1.22)
bigdecimal (4.1.0)
bindata (2.5.1)
bindex (0.8.1)
Expand Down Expand Up @@ -208,10 +208,10 @@ GEM
date (3.5.1)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
devise (4.9.4)
devise (5.0.3)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
railties (>= 7.0)
responders
warden (~> 1.2.3)
diff-lcs (1.6.2)
Expand Down Expand Up @@ -344,7 +344,7 @@ GEM
mini_magick (5.3.1)
logger
mini_mime (1.1.5)
minitest (6.0.2)
minitest (6.0.3)
drb (~> 2.0)
prism (~> 1.5)
msgpack (1.8.0)
Expand Down Expand Up @@ -428,11 +428,11 @@ GEM
psych (5.3.1)
date
stringio
public_suffix (6.0.2)
public_suffix (7.0.5)
puma (6.6.1)
nio4r (~> 2.0)
racc (1.8.1)
rack (3.2.5)
rack (3.2.6)
rack-attack (6.7.0)
rack (>= 1.0, < 4)
rack-cors (3.0.0)
Expand All @@ -442,7 +442,7 @@ GEM
base64 (>= 0.1.0)
logger (>= 1.6.0)
rack (>= 3.0.0, < 4)
rack-session (2.1.1)
rack-session (2.1.2)
base64 (>= 0.1.0)
rack (>= 3.0.0)
rack-test (2.2.0)
Expand Down Expand Up @@ -512,9 +512,9 @@ GEM
io-console (~> 0.5)
request_store (1.7.0)
rack (>= 1.4)
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
responders (3.2.0)
actionpack (>= 7.0)
railties (>= 7.0)
rexml (3.4.2)
rolify (6.0.1)
rspec-core (3.13.5)
Expand Down
Loading