Skip to content

Registration of tasks #1

@Kymer

Description

@Kymer

We want to be able to register a single and periodic task:

registerSingleTask

  • String id
  • String taskName
  • String tag
  • Enum existingWorkPolicy:
    • keep
    • replace
  • TimeInterval initialDelay
  • Enum constraints:
    • requiresNetworkConnectivity
    • requiresExternalPower
  • Enum backoffPolicy
    • exponential
    • linear
  • TimeInterval backoffPolicyDelay
  • String inputData

registerPeriodicTask

  • TimeInterval frequency
  • String id
  • String taskName
  • String tag
  • Enum existingWorkPolicy:
    • keep
    • replace
  • TimeInterval initialDelay
  • Enum constraints:
    • requiresNetworkConnectivity
    • requiresExternalPower
  • Enum backoffPolicy
    • exponential
    • linear
  • TimeInterval backoffPolicyDelay
  • String inputData

We'll start with supporting only BGProcessingTaskRequest for now. Later we can look at BGAppRefreshTaskRequest.

Internally we'll need to keep a complete state of the different tasks.

We need to keep a reference to the tasks in order to know how to behave when a new registration comes in with the same id. Depending on the existingWorkPolicy, the previously registered task needs to be left alone or resubmitted. We also want to be able to cancel all requests with a certain tag. If a task fails it needs to be resubmitted based on the backoffPolicy and backoffPolicyDelay.

For periodic tasks there is a frequency property. Meaning that after each succesful 'run' of the task a new task needs to be submitted with an earliestBeginDate calculated using the frequency that was passed along.

General notes from BGTaskScheduler class docs:

The system runs only tasks registered with identifiers on a whitelist of task identifiers. To add the whitelist, add the identifiers to the Info.plist file.

This is something we'll need to clearly mention in our documentation.

From BGTaskScheduler submit(_:) docs:

Submitting a task request for an unexecuted task that’s already in the queue replaces the previous task request.

There can be a total of 1 refresh task and 10 processing tasks scheduled at any time. Trying to schedule more tasks returns BGTaskScheduler.Error.Code.tooManyPendingTaskRequests.

Useful links:

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions