Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PROD] Fix seeding; sort by date not string; add code coverage; soft delete duplicate and orphaned objectives #2584

Merged
merged 207 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
207 commits
Select commit Hold shift + click to select a range
5b59e92
restore lost changes
GarrettEHill Nov 20, 2024
7c5acc9
add 15 min interval checking
GarrettEHill Nov 21, 2024
1309adc
add support to turn off similarity api too
GarrettEHill Nov 21, 2024
5f20fb4
for testing add current branch for triggering as well
GarrettEHill Nov 21, 2024
71cfedf
Update config.yml
GarrettEHill Nov 21, 2024
00b950d
Update config.yml
GarrettEHill Nov 21, 2024
a72ecf4
add locking system to prevent collisions of interacting with environm…
GarrettEHill Nov 21, 2024
2294fe7
fix name use
GarrettEHill Nov 21, 2024
c5fd264
make executable
GarrettEHill Nov 21, 2024
b13826b
Update config.yml
GarrettEHill Nov 21, 2024
0bfbe93
some updates
GarrettEHill Nov 21, 2024
c097fe5
switch out user token
GarrettEHill Nov 21, 2024
4f4143f
typo
GarrettEHill Nov 21, 2024
bd2fc71
move to script file
GarrettEHill Nov 21, 2024
9c4accd
Update release-lock.sh
GarrettEHill Nov 21, 2024
b7b53ef
Update config.yml
GarrettEHill Nov 21, 2024
3c303a4
debug
GarrettEHill Nov 21, 2024
c2dc15e
Update manage_apps.sh
GarrettEHill Nov 21, 2024
a95692f
Update manage_apps.sh
GarrettEHill Nov 22, 2024
f9cb258
debug
GarrettEHill Nov 22, 2024
0805124
restructure
GarrettEHill Nov 22, 2024
caa9f82
adjust window to be 60 min, also consider system power-on as an activ…
GarrettEHill Nov 22, 2024
f195847
skip if already stopped
GarrettEHill Nov 22, 2024
c905658
Update manage_apps.sh
GarrettEHill Nov 22, 2024
df28da1
Update release-lock.sh
GarrettEHill Nov 22, 2024
3ca394d
debug
GarrettEHill Nov 22, 2024
d942cb6
debug
GarrettEHill Nov 22, 2024
98c4f1b
refactor again
GarrettEHill Nov 22, 2024
cb3aa0e
debugging lock
GarrettEHill Nov 22, 2024
851864a
debug
GarrettEHill Nov 22, 2024
1254dce
refactor
GarrettEHill Nov 22, 2024
e39961e
more debug
GarrettEHill Nov 23, 2024
ff5a536
debug
GarrettEHill Nov 23, 2024
5098b8a
support later debuging
GarrettEHill Nov 23, 2024
64f9c1c
refactor again
GarrettEHill Nov 23, 2024
9359b2f
refactor to use tmp file
GarrettEHill Nov 25, 2024
8f3864a
Update acquire-lock.sh
GarrettEHill Nov 25, 2024
ceb6f53
more adjustments to avoid obfuscation
GarrettEHill Nov 25, 2024
099c36e
Update check-lock.sh
GarrettEHill Nov 25, 2024
5646450
Update check-lock.sh
GarrettEHill Nov 25, 2024
834c333
Update acquire-lock.sh
GarrettEHill Nov 25, 2024
21f2a6e
Merge branch 'main' into TTAHUB-3071/shutdown-unutilized-envs
GarrettEHill Nov 26, 2024
9f9a9ea
refactor to git
GarrettEHill Nov 29, 2024
d51decf
fix some errors
GarrettEHill Nov 29, 2024
8d47443
missing url
GarrettEHill Nov 29, 2024
2cc80a3
Merge branch 'main' into TTAHUB-3071/shutdown-unutilized-envs
GarrettEHill Dec 10, 2024
7c8f663
refactor to use cloud foundry envs
GarrettEHill Dec 10, 2024
4001082
Update config.yml
GarrettEHill Dec 16, 2024
1a9979b
Update config.yml
GarrettEHill Dec 16, 2024
3353c31
Update config.yml
GarrettEHill Dec 16, 2024
46ae615
more coverage
nvms Dec 17, 2024
377b2f8
more coverage
nvms Dec 17, 2024
955366c
more coverage
nvms Dec 17, 2024
c39fbed
more coverage
nvms Dec 17, 2024
301dbea
more coverage
nvms Dec 17, 2024
760a311
more coverage
nvms Dec 17, 2024
8b27f67
more coverage
nvms Dec 17, 2024
45a0d02
more coverage
nvms Dec 17, 2024
07e58a5
add grant replacement logic
GarrettEHill Dec 17, 2024
eaa4316
more coverage
nvms Dec 17, 2024
847daaf
Bring it up to 100
thewatermethod Dec 17, 2024
adf1ffc
Merge branch 'main' into TTAHUB-3734/data-alignment
GarrettEHill Dec 17, 2024
d800bc4
use correct user/pass for each env
GarrettEHill Dec 17, 2024
8dce803
more coverage
nvms Dec 17, 2024
1f163a6
more coverage
nvms Dec 17, 2024
79601bc
correctly parse state
GarrettEHill Dec 17, 2024
50b175a
Merge branch 'main' into TTAHUB-3071/shutdown-unutilized-envs
GarrettEHill Dec 17, 2024
d18356e
fix removing goal while editing another goal
AdamAdHocTeam Dec 17, 2024
4ab6018
fix env processing
GarrettEHill Dec 18, 2024
b12072c
Update manage_apps.sh
GarrettEHill Dec 18, 2024
f29c6d2
remove unnecessary branch
nvms Dec 18, 2024
54b6a1f
cleanup
nvms Dec 18, 2024
0cf0d00
add test for removing a goal while activley editing another
AdamAdHocTeam Dec 18, 2024
d148604
more coverage
nvms Dec 18, 2024
bcf2323
refactor
GarrettEHill Dec 18, 2024
8da59f8
wrap with faker.unique
nvms Dec 18, 2024
571707c
Merge pull request #2548 from HHS/TTAHUB-3545/event-coverage
nvms Dec 18, 2024
bd319ea
more robust checks
GarrettEHill Dec 18, 2024
4c15513
better error handling
GarrettEHill Dec 18, 2024
efb09e2
Merge pull request #2554 from HHS/flakey
nvms Dec 18, 2024
679b1d0
move the acquire to within the manage apps script
GarrettEHill Dec 18, 2024
d0efc1c
missing args
GarrettEHill Dec 18, 2024
2aa95f8
Update acquire-lock.sh
GarrettEHill Dec 19, 2024
2ae092f
Merge pull request #2551 from HHS/al-handle-removal-while-editing
AdamAdHocTeam Dec 19, 2024
4990c8c
cleanup
GarrettEHill Dec 19, 2024
a260991
force to not work on prod
GarrettEHill Dec 19, 2024
dcd73b3
Merge pull request #2498 from HHS/TTAHUB-3071/shutdown-unutilized-envs
GarrettEHill Dec 19, 2024
d0064ae
coverage
nvms Dec 19, 2024
cfcd136
coverage
nvms Dec 19, 2024
52b6228
coverage
nvms Dec 19, 2024
75f0692
coverage
nvms Dec 19, 2024
4a126ff
coverage
nvms Dec 19, 2024
f3d0852
coverage
nvms Dec 19, 2024
119a537
coverage
nvms Dec 19, 2024
c1e466b
coverage
nvms Dec 19, 2024
e3c6058
coverage
nvms Dec 19, 2024
4614918
coverage
nvms Dec 19, 2024
bddadec
coverage
nvms Dec 19, 2024
8d420b5
coverage
nvms Dec 19, 2024
42a9d06
coverage
nvms Dec 19, 2024
2bd42b7
coverage
nvms Dec 19, 2024
0da59fb
more coverage
nvms Dec 19, 2024
21a82f8
more coverage
nvms Dec 19, 2024
27dd9ea
more coverage
nvms Dec 19, 2024
7b8eb82
more coverage
nvms Dec 19, 2024
0473e93
more coverage
nvms Dec 19, 2024
c42fab3
more coverage
nvms Dec 19, 2024
ed801f8
more coverage
nvms Dec 19, 2024
e446d5c
Merge pull request #2557 from HHS/TTAHUB-3574/goalTemplateFieldPrompt…
nvms Dec 19, 2024
28d8c46
Merge pull request #2559 from HHS/TTAHUB-3579/goalsPercentage-coverage
nvms Dec 19, 2024
433bb17
Merge pull request #2561 from HHS/TTAHUB-3557/deliveryMethod-coverage
nvms Dec 19, 2024
6293438
Merge pull request #2562 from HHS/TTAHUB-3560/testingOnly-handlers-co…
nvms Dec 19, 2024
aad1c23
Merge pull request #2563 from HHS/TTAHUB-3568/event-policy-coverage
nvms Dec 19, 2024
3bbb62d
Merge pull request #2565 from HHS/TTAHUB-3699/zip-coverage
nvms Dec 19, 2024
0d7e483
more coverage
nvms Dec 19, 2024
a1cabc9
coverage
nvms Dec 19, 2024
9cc5552
Merge pull request #2558 from HHS/TTAHUB-3577/validFor-coverage
nvms Dec 19, 2024
ce07645
Merge pull request #2564 from HHS/TTAHUB-3572/activityReportObjective…
nvms Dec 19, 2024
9ef4c8b
more coverage
nvms Dec 19, 2024
f81bd44
more coverage
nvms Dec 19, 2024
0e3c384
more coverage
nvms Dec 19, 2024
3d4f719
more coverage
nvms Dec 19, 2024
ffd9169
more coverage
nvms Dec 19, 2024
42696a2
Merge pull request #2556 from HHS/TTAHUB-3573/collaboratorType-coverager
nvms Dec 19, 2024
bee578d
more coverage
nvms Dec 19, 2024
a67e978
more coverage
nvms Dec 19, 2024
892df72
more coverage
nvms Dec 19, 2024
2dd153d
more coverage
nvms Dec 19, 2024
fb8384e
more coverage
nvms Dec 19, 2024
4abf9af
Merge pull request #2567 from HHS/TTAHUB-3702/maintenance-import-cove…
nvms Dec 19, 2024
bcb49e7
more coverage
nvms Dec 19, 2024
18f53b1
Merge pull request #2550 from HHS/TTAHUB-3734/data-alignment
GarrettEHill Dec 19, 2024
42c278e
more coverage
nvms Dec 20, 2024
9a6ea16
Merge pull request #2555 from HHS/TTAHUB-3570/checkIdParamMiddleware-…
nvms Dec 20, 2024
c5b51eb
more coverage
nvms Dec 20, 2024
7dc6f76
Push CLASS score cutoffs back two years
Dec 20, 2024
ca9c50d
clarify comment
Dec 20, 2024
878a06c
Merge pull request #2569 from HHS/ttahub-3714/push_class_ssdi_logic_t…
hardwarehuman Dec 20, 2024
932a795
Merge pull request #2560 from HHS/TTAHUB-3580/topicsByGoalStatus-cove…
nvms Dec 20, 2024
7f04e1e
more coverage
nvms Dec 20, 2024
6c05bb1
Merge pull request #2568 from HHS/TTAHUB-3696/buffer-coverage
nvms Dec 20, 2024
b6233ed
coverage
nvms Dec 20, 2024
516b38e
more coverage
nvms Dec 20, 2024
549f9a3
Revert "more coverage"
nvms Dec 20, 2024
fca0813
more coverage
nvms Dec 20, 2024
04581c3
Merge pull request #2566 from HHS/TTAHUB-3701/maintenance-db-coverage
nvms Dec 20, 2024
496ee3b
coverage
nvms Dec 20, 2024
d4d4696
coverage
nvms Dec 20, 2024
2b12aa5
more coverage
nvms Dec 20, 2024
cfbf6cc
not coverage
nvms Dec 20, 2024
886ae58
more coverage
nvms Dec 20, 2024
5acb210
more coverage
nvms Dec 20, 2024
fd0d1e7
more coverage
nvms Dec 20, 2024
d48d4e3
more coverage
nvms Dec 20, 2024
52ce5cd
Merge pull request #2570 from HHS/TTAHUB-3575/grant-model-coverage
nvms Dec 20, 2024
ec67b50
convert Buffer to Uint8Array
nvms Dec 20, 2024
70bde46
Merge pull request #2571 from HHS/TTAHUB-3542/TTAHUB-3544/s3Queue-sca…
nvms Dec 20, 2024
98479ea
Update config.yml
GarrettEHill Dec 20, 2024
591cdee
Merge pull request #2574 from HHS/config-typo
GarrettEHill Dec 20, 2024
e3301e7
more coverage
nvms Dec 20, 2024
266c81b
more coverage
nvms Dec 20, 2024
28e7fcf
more coverage
nvms Dec 20, 2024
cbab4e3
more coverage
nvms Dec 20, 2024
a1808b2
more coverage
nvms Dec 20, 2024
ad77884
Merge pull request #2572 from HHS/TTAHUB-3543/sessionReports-coverage
nvms Dec 20, 2024
2666536
more coverage
nvms Dec 20, 2024
0839367
Merge pull request #2573 from HHS/TTAHUB-3697/encoding-coverage
nvms Dec 21, 2024
ecd721a
Add coverage for course handlers
thewatermethod Dec 23, 2024
f4c1656
Add tests for group handlers
thewatermethod Dec 23, 2024
c394a18
Testing this labyrinth, part 1
thewatermethod Dec 23, 2024
853f150
Refactor to make testing easier
thewatermethod Dec 23, 2024
e5c3ffa
Further decomposition
thewatermethod Dec 23, 2024
97a03c7
Fix bad import
thewatermethod Dec 23, 2024
2099eb8
add on fail coverage
AdamAdHocTeam Dec 24, 2024
91e4f60
add test for processFilesFromZip
thewatermethod Dec 24, 2024
3171702
finish processZipFileFroms3 test
thewatermethod Dec 24, 2024
015e879
Add more tests for processFilesFromZip
thewatermethod Dec 24, 2024
979be21
add more tests fix others
AdamAdHocTeam Dec 24, 2024
df276e1
Merge pull request #2578 from HHS/mb/TTAHUB-3703/import-process
thewatermethod Jan 2, 2025
c530d39
Merge pull request #2577 from HHS/mb/TTAHUB-3563/group-handlers
thewatermethod Jan 2, 2025
a8eb492
Merge pull request #2576 from HHS/mb/TTAHUB-3736/logNotifications.test
thewatermethod Jan 2, 2025
a44809b
Merge pull request #2575 from HHS/mb/TTAHUB-3562/course-handlers-cove…
thewatermethod Jan 2, 2025
54e9b84
add coverage
AdamAdHocTeam Jan 2, 2025
bfa5fd1
more test coverage
AdamAdHocTeam Jan 2, 2025
412de9f
lint
AdamAdHocTeam Jan 2, 2025
97b5e86
[ttahub-3753] Update hsesUsername for one account.
kryswisnaskas Jan 3, 2025
633bf8e
more test coverage
AdamAdHocTeam Jan 3, 2025
0762477
add another coverage test
AdamAdHocTeam Jan 6, 2025
031233e
deletedAt objectives created on ARs but not on an AR
Jan 6, 2025
1ddbaa6
Merge pull request #2579 from HHS/al-ttahub-3250-mailer-coverage
AdamAdHocTeam Jan 6, 2025
0366646
Merge pull request #2580 from HHS/ttahub-3741/clean_up_orphan_objectives
hardwarehuman Jan 6, 2025
1cc150b
new version and tests
GarrettEHill Jan 6, 2025
c90a1dd
lint
GarrettEHill Jan 6, 2025
66b6f83
lint
GarrettEHill Jan 6, 2025
584f5bb
fix sequelize
GarrettEHill Jan 6, 2025
2f81bb9
lint
GarrettEHill Jan 6, 2025
b851d2a
clean up
GarrettEHill Jan 6, 2025
77814fc
added association
GarrettEHill Jan 6, 2025
1d1cada
unscope no longer needed
GarrettEHill Jan 6, 2025
2b66651
Merge pull request #2582 from HHS/kw-ttahub-3753
kryswisnaskas Jan 7, 2025
4e30b82
Merge pull request #2581 from HHS/TTAHUB-2827/refactor-topicsByGoalSt…
GarrettEHill Jan 7, 2025
315106d
sort by date not string
GarrettEHill Jan 8, 2025
35851b5
Update communicationLog.test.js
GarrettEHill Jan 8, 2025
3f883b6
supress lint issue as its needed for correct sql formating
GarrettEHill Jan 8, 2025
e2aab35
Merge pull request #2585 from HHS/TTAHUB-3761/string-date-sort-order
GarrettEHill Jan 8, 2025
006c574
macos does not like tee
GarrettEHill Jan 9, 2025
66332c3
Merge pull request #2588 from HHS/TTAHUB-3750/resupport-macos
GarrettEHill Jan 9, 2025
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
179 changes: 177 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ executors:
docker:
- image: cimg/aws:2024.03
commands:
install_cf_tools:
description: "Install Cloud Foundry CLI"
steps:
- run:
name: Install CF tools
command: |
# Install Cloud Foundry CLI
wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo apt-key add -
echo "deb https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list
sudo apt-get update
sudo apt-get install -y cf8-cli
# Install plugin needed for connect-to-service
cf install-plugin -f https://github.com/cloud-gov/cf-service-connect/releases/download/v1.1.3/cf-service-connect_linux_amd64
sparse_checkout:
description: "Checkout sparse directories from a specific branch."
parameters:
Expand Down Expand Up @@ -353,6 +366,14 @@ commands:
-p ${<< parameters.cloudgov_password >>} \
-o << pipeline.parameters.cg_org >> \
-s ${<< parameters.cloudgov_space >>}
- run:
name: Acquire Lock
command: |
chmod +x ./automation/ci/scripts/*-lock.sh
./automation/ci/scripts/acquire-lock.sh \
"<< parameters.app_name >>" \
"<< parameters.build_branch >>" \
"<< pipeline.number >>"
- run:
name: Push application with deployment vars
command: |
Expand Down Expand Up @@ -386,6 +407,15 @@ commands:
--var BUILD_COMMIT=<< parameters.build_commit >> \
--var BUILD_NUMBER=<< pipeline.number >> \
--var BUILD_TIMESTAMP="$(date +"%Y-%m-%d %H:%M:%S")"
- run:
name: Release Lock
command: |
chmod +x ./automation/ci/scripts/*-lock.sh
./automation/ci/scripts/release-lock.sh \
"<< parameters.app_name >>" \
"<< parameters.build_branch >>" \
"<< pipeline.number >>"
when: always
# - run:
# name: Push maintenance application
# command: |
Expand Down Expand Up @@ -418,12 +448,28 @@ commands:
-p ${<< parameters.cloudgov_password >>} \
-o << pipeline.parameters.cg_org >> \
-s ${<< parameters.cloudgov_space >>}
- run:
name: Acquire Lock
command: |
chmod +x ./automation/ci/scripts/*-lock.sh
./automation/ci/scripts/acquire-lock.sh \
"tta-automation" \
"<< pipeline.git.branch >>" \
"<< pipeline.number >>"
- run:
name: Migrate database
command: |
cf run-task << parameters.app_name >> \
--command "yarn db:migrate:prod" \
--name "migrate"
- run:
name: Release Lock
command: |
chmod +x ./automation/ci/scripts/*-lock.sh
./automation/ci/scripts/release-lock.sh \
"tta-automation" \
"<< pipeline.git.branch >>" \
"<< pipeline.number >>"
cf_automation_task:
description: "Login to Cloud Foundry space, run automation task, and send notification"
parameters:
Expand Down Expand Up @@ -508,6 +554,14 @@ commands:
-p ${<< parameters.cloudgov_password >>} \
-o << pipeline.parameters.cg_org >> \
-s ${<< parameters.cloudgov_space >>}
- run:
name: Acquire Lock
command: |
chmod +x ./automation/ci/scripts/*-lock.sh
./automation/ci/scripts/acquire-lock.sh \
"tta-automation" \
"<< pipeline.git.branch >>" \
"<< pipeline.number >>"
- run:
name: Start Log Monitoring
command: |
Expand Down Expand Up @@ -579,6 +633,14 @@ commands:
slack_bot_token: $SLACK_BOT_TOKEN
slack_channel: "acf-head-start-eng"
message_text_file: "/tmp/message_file"
- run:
name: Release Lock
command: |
chmod +x ./automation/ci/scripts/*-lock.sh
./automation/ci/scripts/release-lock.sh \
"tta-automation" \
"<< pipeline.git.branch >>" \
"<< pipeline.number >>"
- run:
name: Logout of service account
command: |
Expand Down Expand Up @@ -696,7 +758,7 @@ parameters:
type: string
dev_git_branch: # change to feature branch to test deployment
description: "Name of github branch that will deploy to dev"
default: "main"
default: "TTAHUB-3542/TTAHUB-3544/s3Queue-scanQueue-coverage"
type: string
sandbox_git_branch: # change to feature branch to test deployment
default: "TTAHUB-3678/login"
Expand All @@ -716,6 +778,21 @@ parameters:
manual-trigger:
type: boolean
default: false
env_list:
description: "List of environments to manage (start/stop)"
type: string
default: "DEV,SANDBOX"
space_list:
description: "List of Cloud Foundry spaces corresponding to each environment"
type: string
default: ""
env_state:
description: "State of the environment to change (start, stop, restart, restage)"
type: string
default: "none"
manual-manage-env:
type: boolean
default: false
manual-restore:
type: boolean
default: false
Expand Down Expand Up @@ -1460,6 +1537,46 @@ jobs:
rds_service_name: ttahub-prod
s3_service_name: ttahub-db-backups
backup_prefix: production
manage_env_apps:
executor: docker-executor
parameters:
env_list:
type: string
description: "Comma-separated list of environments to manage (both smarthub and similarity-api)"
default: "<< pipeline.parameters.env_list >>"
env_state:
type: string
description: "Action to perform on apps (start, stop, restart, restage)"
default: "<< pipeline.parameters.env_state >>"
check_activity:
type: boolean
description: "If true, only stop apps if inactive for more than activity_timeout minutes"
default: false
activity_timeout:
type: string
description: "number of minutes considered for inactivity"
default: "60"
steps:
- install_cf_tools
# Sparse checkout the automation scripts
- sparse_checkout:
directories: "automation/ci/scripts"
branch: "<< pipeline.git.branch >>"
# Perform the desired action on environments
- run:
name: Manage Apps
command: |
chmod +x ./automation/ci/scripts/*-lock.sh
chmod +x ./automation/ci/scripts/manage_apps.sh
./automation/ci/scripts/manage_apps.sh \
--env_list "<< parameters.env_list >>" \
--env_state "<< parameters.env_state >>" \
--check_activity "<< parameters.check_activity >>" \
--activity_timeout << parameters.activity_timeout >> \
--cg_api "<< pipeline.parameters.cg_api >>" \
--cg_org "<< pipeline.parameters.cg_org >>" \
--branch "<< pipeline.git.branch >>" \
--build "<< pipeline.number >>"
restore_production_for_processing:
docker:
- image: cimg/base:2024.05
Expand Down Expand Up @@ -1574,11 +1691,14 @@ workflows:
build_test_deploy:
when:
and:
# Ensure the workflow is only triggered when `manual-trigger` is false
# and `env_state` is empty (i.e., it's not for starting/stopping environments)
- equal: [false, << pipeline.parameters.manual-trigger >>]
- equal: [false, << pipeline.parameters.manual-restore >>]
- equal: [false, << pipeline.parameters.manual-process >>]
- equal: [false, << pipeline.parameters.manual-backup >>]
- equal: [false, << pipeline.parameters.manual-full-process >>]
- equal: [false, << pipeline.parameters.manual-manage-env >>]
- equal: [false, << pipeline.parameters.manual-restore-staging >>]
- equal: [false, << pipeline.parameters.manual-restore-sandbox >>]
- equal: [false, << pipeline.parameters.manual-restore-dev >>]
Expand Down Expand Up @@ -1707,6 +1827,61 @@ workflows:
equal: [true, << pipeline.parameters.manual-trigger >>]
jobs:
- backup_upload_production
stop_lower_env_workflow:
triggers:
- schedule:
cron: "0 1 * * 2-6" # Runs at 6 PM PST M-F (1 AM UTC next day)
filters:
branches:
only:
- main
jobs:
- manage_env_apps:
env_state: "stop"
env_list: "<< pipeline.parameters.env_list >>"
start_lower_env_workflow:
triggers:
- schedule:
cron: "0 11 * * 1-5" # Runs at 6 AM EST M-F(11 AM UTC)
filters:
branches:
only:
- main
jobs:
- manage_env_apps:
env_state: "start"
env_list: "<< pipeline.parameters.env_list >>"
manual_manage_env_workflow:
when:
equal: [true, << pipeline.parameters.manual-manage-env >>]
jobs:
- manage_env_apps:
env_state: "<< pipeline.parameters.env_state >>"
env_list: "<< pipeline.parameters.env_list >>"
monitor_and_shutdown_envs:
triggers:
# Every 15 minutes from 11 AM to 11:59 PM UTC (6 AM to 6:59 PM EST, 3 AM to 3:59 PM PST), Monday to Friday
- schedule:
cron: "0,15,30,45 11-23 * * 1-5"
filters:
branches:
only:
- main
- TTAHUB-3071/shutdown-unutilized-envs

# Every 15 minutes from 12 AM to 12:45 AM UTC (7 PM to 8:45 PM EST, 4 PM to 5:45 PM PST), Monday to Friday
- schedule:
cron: "0,15,30,45 0-3 * * 2-6"
filters:
branches:
only:
- main
- TTAHUB-3071/shutdown-unutilized-envs
jobs:
- manage_env_apps:
env_state: "stop"
env_list: "<< pipeline.parameters.env_list >>"
check_activity: true
manual_restore_production:
when:
equal: [true, << pipeline.parameters.manual-restore >>]
Expand Down Expand Up @@ -1750,4 +1925,4 @@ workflows:
when:
equal: [true, << pipeline.parameters.manual-restore-dev >>]
jobs:
- restore_processed_to_dev
- restore_processed_to_dev
59 changes: 59 additions & 0 deletions automation/ci/scripts/acquire-lock.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

# Convert environment to app name if necessary
APP_NAME=$( [ "$1" == "DEV" ] && echo "tta-smarthub-dev" || ([ "$1" == "SANDBOX" ] && echo "tta-smarthub-sandbox") || echo "$1" )
BRANCH=$2
BUILD_ID=$3

# Constants
LOCK_TIMEOUT=7200 # 2 hours in seconds

# Fetch environment variables
LOCK_DATA=$(cf env "$APP_NAME" | grep -A 10 LOCK_APP | sed ':a;N;$!ba;s/\n/ /g' | grep -oP "[{][^}]+[}]")

# Check if lock exists
if [ -n "$LOCK_DATA" ]; then
LOCK_TIMESTAMP=$(echo "$LOCK_DATA" | jq -r '.timestamp')
LOCK_BRANCH=$(echo "$LOCK_DATA" | jq -r '.branch')
LOCK_BUILD_ID=$(echo "$LOCK_DATA" | jq -r '.build_id')

CURRENT_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
TIME_DIFF=$(($(date -d "$CURRENT_TIME" +%s) - $(date -d "$LOCK_TIMESTAMP" +%s)))

if [ $TIME_DIFF -lt $LOCK_TIMEOUT ]; then
echo "App $APP_NAME is locked by branch $LOCK_BRANCH with build ID $LOCK_BUILD_ID."
exit 1
fi

echo "Lock is stale. Attempting to acquire lock..."
fi

# Check if app is restaging
APP_STATE=$(cf apps | grep "$APP_NAME" | awk '{print $2}')
if [ "$APP_STATE" != "started" ] && [ "$APP_STATE" != "stopped" ]; then
echo "App $APP_NAME is currently $APP_STATE. Cannot acquire lock."
exit 1
fi

# Acquire lock
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
LOCK_DATA_JSON=$(jq -n \
--arg branch "$BRANCH" \
--arg build_id "$BUILD_ID" \
--arg timestamp "$TIMESTAMP" \
'{branch: $branch, build_id: $build_id, timestamp: $timestamp}')

cf set-env "$APP_NAME" LOCK_APP "$LOCK_DATA_JSON"

# Validate the lock
LOCK_DATA=$(cf env "$APP_NAME" | grep -A 10 LOCK_APP | sed ':a;N;$!ba;s/\n/ /g' | grep -oP "[{][^}]+[}]")
VALID_BRANCH=$(echo "$LOCK_DATA" | jq -r '.branch')
VALID_BUILD_ID=$(echo "$LOCK_DATA" | jq -r '.build_id')

if [ "$VALID_BRANCH" == "$BRANCH" ] && [ "$VALID_BUILD_ID" == "$BUILD_ID" ]; then
echo "Lock successfully acquired for app $APP_NAME."
exit 0
else
echo "Failed to acquire lock for app $APP_NAME."
exit 1
fi
Loading
Loading