-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8ea43f
commit 64bd262
Showing
8 changed files
with
2,250 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Delete unused rooms | ||
|
||
env: | ||
DIFF: 2678400 # 31 day | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 0 1 * *' | ||
|
||
concurrency: | ||
group: "clean-db" | ||
|
||
jobs: | ||
clean-db: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Save service-account-key.json file | ||
env: | ||
FIREBASE_SERVICE_ACCOUNT_KEY: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_KEY }} | ||
run: echo "$FIREBASE_SERVICE_ACCOUNT_KEY" >> service-account-key.json | ||
|
||
- name: Build the app | ||
run: docker build -t watch-together-cleaner --target clean-db . | ||
|
||
- name: Run the container | ||
run: docker run -e DIFF=$DIFF watch-together-cleaner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ node_modules | |
!.env.example | ||
vite.config.js.timestamp-* | ||
vite.config.ts.timestamp-* | ||
service-account-key.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import admin from 'firebase-admin'; | ||
import serviceAccount from './service-account-key.json' assert { type: "json" }; | ||
import firebaseConfig from './src/firebase-config.json' assert { type: "json" }; | ||
|
||
const diff = process.argv[2]; | ||
const now = Math.round(new Date().getTime() / 1000); | ||
|
||
admin.initializeApp({ | ||
credential: admin.credential.cert(serviceAccount), | ||
databaseURL: firebaseConfig.databaseURL | ||
}); | ||
|
||
const main = async function() { | ||
const root = admin.database().ref('room'); | ||
const promises = []; | ||
let count = 0; | ||
|
||
process.stdout.write('Started...\n'); | ||
(await root.once('value')).forEach(childSnapshot => { | ||
const task = (async function () { | ||
const timestamp = childSnapshot.child('timestamp').val(); | ||
if (typeof timestamp !== 'number') { | ||
process.stdout.write(`room#${childSnapshot.key}\twrong type: ${typeof timestamp}\n`); | ||
} else if (timestamp < now - diff) { | ||
process.stdout.write(`room#${childSnapshot.key}\tupdated ${Math.round((now - timestamp) / 60 / 60 / 24)} hours ago\n`); | ||
} else if (timestamp > now + diff) { | ||
process.stdout.write(`room#${childSnapshot.key}\tupdated ${Math.round((timestamp - now) / 60 / 60 / 24)} hours ahead (in future)\n`); | ||
} else { | ||
return; | ||
} | ||
await childSnapshot.ref.remove(); | ||
++count; | ||
})(); | ||
promises.push(task); | ||
}); | ||
|
||
await Promise.all(promises); | ||
process.stdout.write(`\nDone:\n- ${promises.length} rooms total\n- ${count} rooms deleted\n- ${promises.length - count} rooms left\n`); | ||
}; | ||
|
||
main().catch(e => process.stderr.write(e.toString())).finally(() => process.exit(0)); |
Oops, something went wrong.