Firebase Server SDK-如何安排任务? [英] Firebase Server SDK - How do I schedule a task?

查看:42
本文介绍了Firebase Server SDK-如何安排任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被告知要安排任务在云中,以便对Firebase中的实时数据库执行任务,我需要使用Server SDK.

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.

假设我正在使用以下代码将数据保存到Firebase数据库中:

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);

但是我想作为明天的任务上传.我的意思是,这将节省TOMORROW,而不是立即运行此代码.

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.

我准备好日历:

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

那么,如何使用Firebase Server SDK保存任务?这些文档没有提供明确的答案,因为我唯一能看到的就是像实时数据库一样保存数据.

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.

推荐答案

当前,您无法在Firebase的服务器上运行代码.有2种解决方案供您2解决此问题:

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. 您可以使用 Firebase队列,然后在Node.js中运行代码
  2. 您可以使用其他库,例如 Microsoft Azure (我还没有尝试过,我不确定它是否提供Android的Job Scheduling )
  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)

但是,Firebase正在开发名为 Firebase Trigger 的东西,它可以解决我们的问题,但是仍然没有确定发布日期的情况下仍未发布.

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.

这篇关于Firebase Server SDK-如何安排任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆