SwiftQueue
SwiftQueue copied to clipboard
RepeatConstraint not working as expected
I am trying to write a small app that would run a job at set intervals, just like a cron job. To achieve this, I have used the period method just like in the documentation, the following way:
JobBuilder(type: MyJob.type)
.persist()
.singleInstance(forId: "myjob", override: true)
.retry(limit:.unlimited)
.periodic(limit: Limit.unlimited, interval: settings.backgroundTestFrequencyMinutes * 60)
.schedule(manager: queueManager)
However, this causes the job to run every time the app opens. I would only like to run on the predefined schedule.
I have also tried with setting executor: .background
. With this method, the job never runs. This is because the RepeatConstraint always returns false on the run
method when the executor is background. Because of this, the job can never be triggered and the schedule only starts after one successful completion (which can never be triggered).
Moreover, the Executor enum's documentation suggests that the job will run only when the app is in background/foreground (for example by observing UIApplication.shared.applicationState
), which it does not.