Skip to content

⬆️ Improve result code from a Background Task #23

Open
@timrijckaert

Description

@timrijckaert

Actually this was an idea we already discussed with @jeremie-movify and @petermnt before.
The return of a boolean as the result of a background job was a MVP approach and might be insufficient.

Ideally we would want to return some sort of enum representing the success state of a background task.

Android already expects either a:

  • Result.failure()
    • Used to indicate that the work completed with a permanent failure. Any work that depends
      on this will also be marked as failed and will not be run. If you need child workers
      to run, you need to return Result.Success() failure indicates a permanent
      stoppage of the chain of work.

  • Result.success()
    • Used to indicate that the work completed successfully. Any work that depends on this
      can be executed as long as all of its other dependencies and constraints are met.

  • Result.Retry()
    • Used to indicate that the work encountered a transient failure and should be retried with
      backoff.

As of now (0.0.12) the plugin will map the returning bool as following:

  • false -> Result.retry()
  • true -> Result.success()

I thought the iOS return code was similarly mapped.

We could then have something like:

void callbackDispatcher() {
  var result = Result.retry
  Workmanager.executeTask((task) async {
    switch (task) {
      case simpleTaskKey:
       print("do some background work");
       result = Result.success
        break;
    }

    return Future.value(result);
  });
}

Originally posted by @timrijckaert in #20 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions