mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-15 15:02:49 +01:00
refactor: remove the random delay!
Chances of conflict is pretty low since it's saved in ms so can just remove it. Signed-off-by: KaiserBh <kaiserbh@proton.me>
This commit is contained in:
parent
d17aa201d5
commit
235b03bcba
@ -65,12 +65,8 @@ class SyncDataJob(private val context: Context, workerParams: WorkerParameters)
|
|||||||
fun setupTask(context: Context, prefInterval: Int? = null) {
|
fun setupTask(context: Context, prefInterval: Int? = null) {
|
||||||
val syncPreferences = Injekt.get<SyncPreferences>()
|
val syncPreferences = Injekt.get<SyncPreferences>()
|
||||||
val interval = prefInterval ?: syncPreferences.syncInterval().get()
|
val interval = prefInterval ?: syncPreferences.syncInterval().get()
|
||||||
|
|
||||||
if (interval > 0) {
|
if (interval > 0) {
|
||||||
// Generate a random delay in minutes (e.g., between 0 and 15 minutes) to avoid conflicts.
|
|
||||||
val randomDelay = Random.nextInt(0, 16)
|
|
||||||
|
|
||||||
val randomDelayMillis = TimeUnit.MINUTES.toMillis(randomDelay.toLong())
|
|
||||||
|
|
||||||
val request = PeriodicWorkRequestBuilder<SyncDataJob>(
|
val request = PeriodicWorkRequestBuilder<SyncDataJob>(
|
||||||
interval.toLong(),
|
interval.toLong(),
|
||||||
TimeUnit.MINUTES,
|
TimeUnit.MINUTES,
|
||||||
@ -78,7 +74,7 @@ class SyncDataJob(private val context: Context, workerParams: WorkerParameters)
|
|||||||
TimeUnit.MINUTES,
|
TimeUnit.MINUTES,
|
||||||
)
|
)
|
||||||
.addTag(TAG_AUTO)
|
.addTag(TAG_AUTO)
|
||||||
.setInitialDelay(randomDelayMillis, TimeUnit.MILLISECONDS)
|
// No initial delay is needed, remove the randomDelayMillis
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
context.workManager.enqueueUniquePeriodicWork(TAG_AUTO, ExistingPeriodicWorkPolicy.UPDATE, request)
|
context.workManager.enqueueUniquePeriodicWork(TAG_AUTO, ExistingPeriodicWorkPolicy.UPDATE, request)
|
||||||
|
Loading…
Reference in New Issue
Block a user