gpt4 book ai didi

java - Android 中的 WorkManager Schedule_requested_at time 等于 -1。什么意思?

转载 作者:行者123 更新时间:2023-12-02 04:32:03 26 4
gpt4 key购买 nike

我正在使用 WorkManager 来安排一些定期工作,以将本地数据库与远程数据库同步。几个月来一切都运行良好,直到有一天数据库停止了同步。我通过 Stetho 发现我所有的 Work 实例的“schedule_requested_at”值都等于 -1。

PeriodicWorkRequest refreshCpnWork = new PeriodicWorkRequest.Builder(MainWorker.class, Constants.WORKER_INTERVAL_MIN, TimeUnit.MINUTES)
.addTag("PeriodicWork")
.build();

WorkManager.getInstance().enqueue(refreshCpnWork);

These are the scheduled works, in normal conditions

这就是我安排工作的方式,正如我所说,几个月来效果很好。但从某个时刻开始,它停止安排我的工作,并且在图片中,不是正确的时间戳,而是 -1。

最佳答案

我发现schedule_requested_at中-1的含义是什么。

来自 WorkSpec.java(工作运行时:1.0.0-alpha11):

/**
* This field tells us if this {@link WorkSpec} instance, is actually currently scheduled and
* being counted against the {@code SCHEDULER_LIMIT}. This bit is reset for PeriodicWorkRequests
* in API < 23, because AlarmManager does not know of PeriodicWorkRequests. So for the next
* request to be rescheduled this field has to be reset to {@code SCHEDULE_NOT_REQUESTED_AT}.
* For the JobScheduler implementation, we don't reset this field because JobScheduler natively
* supports PeriodicWorkRequests.
*/
@ColumnInfo(name = "schedule_requested_at")
public long scheduleRequestedAt = SCHEDULE_NOT_REQUESTED_YET;

如果值为 -1,则工作已插入表中,但尚未安排。

在我的例子中,有太多的 Work 实例来安排新的内容,下面这个查询来自 WorkSpecDao.java:

/**
* @return The List of {@link WorkSpec}s that are eligible to be scheduled.
*/
@Query("SELECT * FROM workspec WHERE "
+ "state=" + WorkTypeConverters.StateIds.ENQUEUED
// We only want WorkSpecs which have not been previously scheduled.
+ " AND schedule_requested_at=" + WorkSpec.SCHEDULE_NOT_REQUESTED_YET
+ " LIMIT "
+ "(SELECT MAX(:schedulerLimit" + "-COUNT(*), 0) FROM workspec WHERE"
+ " schedule_requested_at<>" + WorkSpec.SCHEDULE_NOT_REQUESTED_YET
+ " AND state NOT IN " + COMPLETED_STATES
+ ")"
)
List<WorkSpec> getEligibleWorkForScheduling(int schedulerLimit);

关于java - Android 中的 WorkManager Schedule_requested_at time 等于 -1。什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56576777/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com