Frequently Asked Questions

How often will my jobs run?

On iOS, it depends. iOS schedules jobs to run when the user generally is about to use your app. It is a pre-emptive task. On Android, roughly every 15mins unless Doze is enabled. Doze will look at things like battery and time of day similar to how iOS does things.

My iOS job isn't repeating

If it ran once and you’ve set repeat to true on the JobInfo, it will run, but again - iOS needs a few days to learn how the user uses your app. If you need more control on when things run, jobs is not the answer. You should consider looking at push notifications

How long does the background sync let me have on iOS

30 seconds and not a penny more

How do I schedule periodic jobs?

All jobs are considered periodic with or without criteria

How many jobs can I run?

Technically as many as you want… BUT this was built with mobile timeslicing in mind (ie. iOS). Your job set needs to complete within that timeslice as we don’t set job ordering currently

Should I try/catch my job code

It is not required, like all other delegates in Shiny. However, note that background logging will not output to a console/debug/etc. You need something like a file based logger registered or something like our Shiny.Logging.AppCenter. Shiny automatically puts a try/catch around your job code and will log the exception for you.

Why can't I set the next runtime

From a true runtime perspective you can’t, however, inside you job you can set add/update the job parameters or check the last runtime on the job info to see if you want to run. Example below:

public class SampleJob : Shiny.NotifyPropertyChanged, IJob
    // jobs are stateful services
    DateTime? lastRunUtc;
    public DateTime? LastRunUtc 
        get => this.lastRunUtc; 
        set => this.Set(ref this.lastRunUtc, value);

    public async Task Run(JobInfo jobInfo, CancellationToken cancelToken)
        var runJob = false;
        if (this.LastRunUtc == null) // job has never run
            runJob = true;

        else if (DateTime.UtcNow > this.LastRunUtc.AddHours(1))
            runJob = true;  // its been at least an hour since the last run

        if (runJob)
            ... do your job