Giter Club home page Giter Club logo

Comments (2)

lucas34 avatar lucas34 commented on August 23, 2024

As long as the app stays in memory, All the jobs will stay as well.
Persisted Job is only when you kill the app, once you restart, you may want to retrieve those pending jobs.

from swiftqueue.

afterthought avatar afterthought commented on August 23, 2024

Take this for what it's worth, but I figured I would chime in with how I coded this in an app that uses SwiftQueue. Thanks btw, @lucas34... My queues are running API GET/POST operations in the background and I wanted to ensure that anything inflight was finished (didn't seem to make sense to use apple's NSURLSession background support here)... I know this won't be super easy to follow without seeing the rest of the app code, but the basic objective is to ensure that any inflight API calls can complete and that the state of the application can be updated/persisted with the results before the app gets frozen. Maybe this will help someone else someday.

func applicationDidEnterBackground(_ application: UIApplication) {
    taskId = application.beginBackgroundTask(withName: "StopJobs", expirationHandler: {
        application.endBackgroundTask(self.taskId)
    })

    if taskId != UIBackgroundTaskInvalid {
        DispatchQueue.global(qos: .background).async {
            os_log("Temporarily pause ALL swiftqueue jobs while we drain NETWORK operationQueue")
            queueManager.pause()
            self.drainNetworkOperations()

            os_log("Set to background state - triggers Post/fetch job cancellation")
            OperationQueue.main.addOperation {
                store.dispatch(SetBackgroundState(appInBackground: true))
            }
            os_log("Restart swiftqueue jobs. Post/fetch jobs are still cancelled now.")
            queueManager.start()
            os_log("Drain MAIN operationQueue, to ensure all work items are finished.")
            self.drainActiveJobMainOperations()

            os_log("Drain JobQueues.")
            queueManager.waitUntilAllOperationsAreFinished()

            application.endBackgroundTask(self.taskId)
        }

    }

} 

from swiftqueue.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.