Remove midnight refresh worker

pull/2872/head
Alex Baker 7 months ago
parent 4ddb7816f1
commit 95c351e9fd

@ -95,7 +95,6 @@ class Tasks : Application(), Configuration.Provider {
NotificationSchedulerIntentService.enqueueWork(context)
workManager.get().apply {
updateBackgroundSync()
scheduleMidnightRefresh()
scheduleBackup()
scheduleConfigRefresh()
updatePurchases()

@ -42,7 +42,7 @@ FROM (
WHERE completed = 0 AND deleted = 0
)
""")
abstract suspend fun nextRefresh(now: Long = System.currentTimeMillis()): Long
abstract suspend fun nextRefresh(now: Long = now()): Long
@Query("SELECT * FROM tasks WHERE _id = :id LIMIT 1")
abstract suspend fun fetch(id: Long): Task?

@ -1,25 +0,0 @@
package org.tasks.jobs
import android.content.Context
import androidx.hilt.work.HiltWorker
import androidx.work.WorkerParameters
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import org.tasks.LocalBroadcastManager
import org.tasks.analytics.Firebase
@HiltWorker
class MidnightRefreshWork @AssistedInject constructor(
@Assisted context: Context,
@Assisted workerParams: WorkerParameters,
firebase: Firebase,
private val workManager: WorkManager,
private val localBroadcastManager: LocalBroadcastManager) : RepeatingWorker(context, workerParams, firebase) {
override suspend fun run(): Result {
localBroadcastManager.broadcastRefresh()
return Result.success()
}
override suspend fun scheduleNext() = workManager.scheduleMidnightRefresh()
}

@ -7,6 +7,9 @@ import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import org.tasks.LocalBroadcastManager
import org.tasks.analytics.Firebase
import org.tasks.data.TaskDao
import org.tasks.date.DateTimeUtils
import kotlin.math.min
@HiltWorker
class RefreshWork @AssistedInject constructor(
@ -15,6 +18,7 @@ class RefreshWork @AssistedInject constructor(
firebase: Firebase,
private val localBroadcastManager: LocalBroadcastManager,
private val workManager: WorkManager,
private val taskDao: TaskDao,
) : RepeatingWorker(context, workerParams, firebase) {
override suspend fun run(): Result {
@ -22,5 +26,6 @@ class RefreshWork @AssistedInject constructor(
return Result.success()
}
override suspend fun scheduleNext() = workManager.scheduleRefresh()
override suspend fun scheduleNext() =
workManager.scheduleRefresh(min(taskDao.nextRefresh(), DateTimeUtils.midnight()))
}

@ -1,6 +1,7 @@
package org.tasks.jobs
import android.net.Uri
import com.todoroo.andlib.utility.DateUtilities.now
import com.todoroo.astrid.data.Task
import org.tasks.BuildConfig
import org.tasks.data.CaldavAccount
@ -20,9 +21,7 @@ interface WorkManager {
fun updateBackgroundSync()
suspend fun scheduleRefresh()
fun scheduleMidnightRefresh()
suspend fun scheduleRefresh(timestamp: Long = now() + 5_000)
fun scheduleNotification(scheduledTime: Long)
@ -40,7 +39,6 @@ interface WorkManager {
val REMOTE_CONFIG_INTERVAL_HOURS = if (BuildConfig.DEBUG) 1 else 12.toLong()
const val TAG_BACKUP = "tag_backup"
const val TAG_REFRESH = "tag_refresh"
const val TAG_MIDNIGHT_REFRESH = "tag_midnight_refresh"
const val TAG_SYNC = "tag_sync"
const val TAG_BACKGROUND_SYNC = "tag_background_sync"
const val TAG_REMOTE_CONFIG = "tag_remote_config"

@ -45,7 +45,6 @@ import org.tasks.jobs.SyncWork.Companion.EXTRA_IMMEDIATE
import org.tasks.jobs.WorkManager.Companion.REMOTE_CONFIG_INTERVAL_HOURS
import org.tasks.jobs.WorkManager.Companion.TAG_BACKGROUND_SYNC
import org.tasks.jobs.WorkManager.Companion.TAG_BACKUP
import org.tasks.jobs.WorkManager.Companion.TAG_MIDNIGHT_REFRESH
import org.tasks.jobs.WorkManager.Companion.TAG_MIGRATE_LOCAL
import org.tasks.jobs.WorkManager.Companion.TAG_REFRESH
import org.tasks.jobs.WorkManager.Companion.TAG_REMOTE_CONFIG
@ -140,11 +139,8 @@ class WorkManagerImpl(
}
}
override suspend fun scheduleRefresh() =
enqueueUnique(TAG_REFRESH, RefreshWork::class.java, taskDao.nextRefresh())
override fun scheduleMidnightRefresh() =
enqueueUnique(TAG_MIDNIGHT_REFRESH, MidnightRefreshWork::class.java, midnight())
override suspend fun scheduleRefresh(timestamp: Long) =
enqueueUnique(TAG_REFRESH, RefreshWork::class.java, timestamp)
override fun scheduleNotification(scheduledTime: Long) {
val time = max(DateUtilities.now(), scheduledTime)

Loading…
Cancel
Save