lucas34 / SwiftQueue

Job Scheduler for IOS with Concurrent run, failure/retry, persistence, repeat, delay and more
MIT License
410 stars 43 forks source link

RepeatConstraint not working as expected #439

Closed moray95 closed 2 months ago

moray95 commented 2 months ago

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.

stale[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.