-1

I was told to schedule tasks in the cloud to do tasks to my Realtime Database in Firebase I need to use the Server SDK.

Let's say I'm saving data to the Firebase database using this code:

DatabaseReference usersRef = ref.child("users");

Map<String, User> users = new HashMap<String, User>();
users.put("alanisawesome", new User("June 23, 1912", "Alan Turing"));
users.put("gracehop", new User("December 9, 1906", "Grace Hopper"));

usersRef.setValue(users);

But I want to upload this as a task for tomorrow. What I mean is, this will save TOMORROW instead of the instant this code gets run.

I have a Calendar ready:

Calendar cal = Calendar.getInstance();
cal.add(DAY_OF_MONTH,1); //This could be wrong, but I'm just telling you I have a Calendar ready, so ignore any errors in this code

So, how can I save a task using the Firebase Server SDK? The docs don't provide a clear answer for this since the only thing I can see is saving data just like the Realtime Database.

Ali Bdeir
  • 4,151
  • 10
  • 57
  • 117
  • There is currently no way to run your code to run on Firebase's servers. See http://stackoverflow.com/questions/31340542/how-to-write-custom-code-logic-when-using-firebase – Frank van Puffelen Aug 14 '16 at 15:15

3 Answers3

1

If you have a 3rd party server (that uses the Firebase SDK, server SDK), you can poll all saved data and will call either a TImerService or a CRON JOB to have it persist the list to the Firebase Realtime Database.

It will depend on your server implementation, but a queueing implementation indicated above would work in your scenario.

An example of CRON job to call a webservice (in your case, the one that will persist all queued items to Firebase) can be found on this StackOverflow page. For TimerService, you can refer to its documentation

Happy coding!

Community
  • 1
  • 1
adjuremods
  • 2,938
  • 2
  • 12
  • 17
  • Thanks, but your links are in another computer languge. I'm pretty sure Firebase itself has the option, as someone previously marked. +1 for trying. – Ali Bdeir Aug 14 '16 at 08:36
0

Create a broadcast reciever and define it in your manifest. Override onRecieve and put your firebase code there. Then define the receiver in your manifest. Create a pendingIntent using the Receiver and set it in a AlarmManager, by using the setExact() method and pass in the pendingIntent.

Linxy
  • 2,525
  • 3
  • 22
  • 37
0

Currently there is no way for you to run your code on Firebase's server. There are 2 options for you 2 solve this:

  1. You could use Firebase Queue and run your code in Node.js
  2. You could use a different library such as Microsoft Azure (I still haven't tried this yet, I'm not sure if it provides Job Scheduling for Android)

However, Firebase is working on something called Firebase Trigger, which will solve our problem, however it is still not released with no confirmed release date.

Ali Bdeir
  • 4,151
  • 10
  • 57
  • 117