Reputation: 369
I'm building a crowd-funding app and every campaign on my app has a target date. How do I write a function to automatically delete that campaign or shift it elsewhere once the target date is reached?
More specifically, I want to move the campaign from ref('/Fund/{Campaign_ID}')
to ref('/Timed_out/{Campaign_ID}')
.
PS: Please don't suggest manual cron-jobs. It would be impossible for me to keep track of who starts a campaign if the number of users and volume of campaigns grows.
My database in JSON(The important bit):
{
"Fund" : {
"-LEEy7uxXEeI4AJuePoB" : {
"amount_funded" : 1400000,
"artist_name" : "Sean Roldan and Friends",
"genre" : "Indian Blues and Jazz",
"image_url" : "https://firebasestorage.googleapis.com/v0/b/artcall-f8f1a.appspot.com/o/profile_images%2Fthumbs%2Fseanroldan.jpg?alt=media&token=6414d8d6-e8a8-487e-baf3-0d36d017a205",
"percent_funded" : 0,
"perf_location" : "Chennai",
"reward_amt" : 6000,
"target_amount" : 1750000,
"target_date" : 1566568176731,
"time_left" : 1566568176731,
"total_backers" : 0
}
},
"Fund_Project_Request" : {
"-LEEy7uxXEeI4AJuePoB" : {
"as123132" : 2,
"asd123132" : 2,
"asdf123asdf21" : 2
}
},
"Loyalty_Points" : {
"value" : 3000
},
Upvotes: 0
Views: 342
Reputation: 600006
You can use a single cron-job to trigger at an interval, and then scan for expired data. In fact, that's the most common way to implement time-to-live on Firebase at the moment.
Upvotes: 1