Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registration of tasks #1

Open
Kymer opened this issue Oct 28, 2019 · 3 comments
Open

Registration of tasks #1

Kymer opened this issue Oct 28, 2019 · 3 comments
Assignees

Comments

@Kymer
Copy link

Kymer commented Oct 28, 2019

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:

@phranck
Copy link

phranck commented Dec 5, 2019

@Kymer @olivierscalais JFYI: I'm actively working on our (Open-Xchange) fork of this manager for our Open Source Flutter project OX COI Messenger. I made lots of changes and already added registration for App Refresh Tasks. Please see here.

@AAverin
Copy link

AAverin commented Jun 17, 2020

Hi guys. Your project seems to be the only one so far trying to leverage iOS BackgroundTask API.
Is there any progress on this already or was the project frozen so far?

@petermnt
Copy link
Member

Hi @AAverin , we are currently not actively developing this project.
We are open to pull requests though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants