Skip to content

Commit

Permalink
Fixes from code review. Docs on database backup/restore
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewKahr committed Jun 5, 2024
1 parent 42782bd commit a43b241
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 25 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ jobs:
- name: Deploy to Firebase
uses: w9jds/firebase-action@v13.10.2
with:
args: deploy
env:
GCP_SA_KEY: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_UNITY_CI_VERSIONS }}'
- name: Cleanup Firebase Test
uses: w9jds/firebase-action@v13.10.2
with:
args: functions:delete testFunction --force
args: deploy --except functions:testFunction
env:
GCP_SA_KEY: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_UNITY_CI_VERSIONS }}'
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,14 @@ Completed CiJobs are reported to Discord.
## Ingeminator

TODO - Describe how it works

## Database Backup

The firestore database can be backed up with the following command:
`yarn run backfire export ./export/versioningBackendBackup --project unity-ci-versions --keyFile <PATH_TO_GOOGLE_CLOUD_SERVICE_ACCOUNT_KEYFILE.json>`

Similarly, it can be used to restore a backup with:
`yarn run backfire import ./export/versioningBackendBackup --project unity-ci-versions --keyFile <PATH_TO_GOOGLE_CLOUD_SERVICE_ACCOUNT_KEYFILE.json>`

You likely would want to empty the database before restoring but you can also use flags like overwrite, merge, etc to control the restoration
rules.
23 changes: 10 additions & 13 deletions functions/src/service/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ export class Discord {
});

await this.instance.connect();
await this.becomeReady();

let secondsWaited = 0;
while (!this.instance?.startTime) {
await new Promise((resolve) => setTimeout(resolve, 1000));
secondsWaited += 1;

if (secondsWaited >= 15) {
throw new Error('Bot never became ready');
}
}
}

public async sendDebugLine(message: 'begin' | 'end') {
Expand Down Expand Up @@ -92,18 +101,6 @@ export class Discord {
return isSent;
}

async becomeReady(): Promise<void> {
let secondsWaited = 0;
while (!this.instance?.startTime) {
await new Promise((resolve) => setTimeout(resolve, 1000));
secondsWaited += 1;

if (secondsWaited >= 15) {
throw new Error('Bot never became ready');
}
}
}

public async disconnect(): Promise<void> {
if (!this.instance) return;

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
},
"homepage": "https://github.com/game-ci/versioning-backend#readme",
"dependencies": {
"@google-cloud/firestore": "^7.8.0",
"firebase-tools": "^13.10.2",
"firestore-backfire": "^2.5.3",
"prettier": "^2.8.7"
},
"devDependencies": {
"firebase-tools": "^13.10.2"
}
}
Loading

0 comments on commit a43b241

Please sign in to comment.