使用Firebase作业调度程序安排定期作业 [英] Schedule recurring job using firebase job dispatcher

查看:79
本文介绍了使用Firebase作业调度程序安排定期作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试每10分钟将android设备的位置发布到服务器.我正在使用Firebase作业调度程序执行此操作

I am trying to post the location of the android device to server every 10 minutes. I am using firebase job dispatcher to do this

FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
Job myJob = dispatcher.newJobBuilder()
    .setService(UpdateLocationService.class)
    .setRecurring(true)
    .setTrigger(Trigger.executionWindow(10, 20))
    .setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
    .setTag("location-update-job")
    .setLifetime(Lifetime.FOREVER)
    .build();
dispatcher.mustSchedule(myJob);

UpdateLocationService获取位置并将其发送到服务器.

UpdateLocationService gets the location and sends to server.

我的问题:大部分情况下工作正常.唯一的事情是,工作安排的进度相差4m,6m,7m,8m,10m,16m,23m ...

My problem: Things are mostly working fine. Only thing is, the jobs are getting scheduled with a difference of 4m, 6m, 7m, 8m, 10m, 16m, 23m...

有人可以帮我理解一下吗.

Can some one please help me understand going on.

更新:我希望该位置在10到20分钟内出现一次.在上面的代码中,该值太低,仅用于测试目的

Update: I want the location once in 10-20 minutes. In the above code, the value is too low just for the testing purposes

推荐答案

还:

Trigger.executionWindow(windowStart, windowEnd)

以秒为单位期望windowStartwindowEnd.根据您的要求,您希望窗口为10分钟.所以你应该使用类似的东西:

expects the windowStart and windowEnd in seconds. As per your requirement, you want the window to be 10 mins. So you should use something like:

Trigger.executionWindow(10*60, 20*60)

这篇关于使用Firebase作业调度程序安排定期作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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