-
Notifications
You must be signed in to change notification settings - Fork 102
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
Showing
3 changed files
with
30 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,3 +138,4 @@ build | |
# Other | ||
.env | ||
build/ | ||
.firebase-secrets.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { messagesCollection } from '../utilities/firebaseInit' | ||
const cron = require('node-cron') | ||
|
||
//Schedule tasks to be run on the server | ||
export const scheduleCron = () => { | ||
cron.schedule('*/30 * * * * *', function() { | ||
console.log('Deleting old messages every 30s.') | ||
|
||
//Deleter action, takes in a unix timestamp and deletes | ||
//everything older than that | ||
const expiryTime = Number(process.env.message_duration) //Set to 1 minute for testing purposes | ||
|
||
const q = messagesCollection.orderByChild('timeSent').endAt(Date.now() - expiryTime) | ||
|
||
q.on('value', (querySnapshot)=> { | ||
querySnapshot.forEach(async (doc) => { | ||
//Delete the doc here | ||
console.log(doc.id) | ||
await doc.ref.delete() | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
|
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