I'm trying to realise a leaderboard for my App which should rewrite every 24h, but I can't get it to work... The job doesn't even start.
This is all I found about the function, but it doesn't help me. https://firebase.google.com/docs/functions/schedule-functions
And this is my function:
exports.leaderboardjob = functions.region('europe-west1').pubsub.schedule( '0 0 * * *').onRun(async (context) => {
await leaderboard();
console.log("job done");
return null;
});
async function leaderboard(){
const rdb = admin.firestore();
const ref = rdb.ref('users');
try {
await ref.orderByChild('xp').limitToLast(2).on('child_added', (snapshot) => { //test first with 2 results
console.log(snapshot.key);
});
} catch (error) {
console.log('error: ' + error.message);
}
return{
result: ok
}
}
I already moved the function to my region europe-west1 like all my other functions.
error that I get back when I call this function (leaderboardjob) manually:
{"@type":"type.googleapis.com/google.cloud.scheduler.logging.AttemptFinished", "jobName":"projects/censored/locations/europe-west1/jobs/firebase-schedule-leaderboardjob-europe-west1", "pubsubTopic":"projects/censored/topics/firebase-schedule-leaderboardjob-europe-west1", "status":"UNAUTHENTICATED", "targetType":"PUB_SUB"}
Maybe its just not possible, if not: can someone explain me how to realise something like this with functions?
EDIT: I forgot to tell, that I gave the function the role with a new account "pubsub.subscriber"
I just deleted the whole function and tested it with a new name.
I don't know why, but this worked...
You don't even need to add a role. Everything works just fine.