Comments (2)
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.
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)
- Last persisted job appears to run twice (before and after app restart) HOT 5
- How to cancel a particular job in version 5 now that UUID has been removed HOT 3
- Possibility of running N concurrent jobs inside a queue HOT 2
- WatchOS support HOT 2
- Periodic run just once HOT 2
- EXC_BAD_ACCESS in the method createQueue HOT 4
- The waitUntilAllOperationsAreFinished method is called before completion HOT 2
- Not able to access registerForBackgroundTask method in SwiftQueueManager+BackgroundTask HOT 2
- <compiler-generated> SwiftQueueManager.enqueue(info:) HOT 3
- Support NSOperation Dependency HOT 2
- Crash when enqueue from multiples thread HOT 5
- <compiler-generated> SwiftQueueManager.enqueue(info:) #408 HOT 1
- Is it possible to start Foreground initiated jobs that continue background execution? HOT 2
- Replace Reachability dependency with NWPathMonitor usage HOT 4
- Get additional info for a job HOT 10
- extensible DefaultConstraintMaker for persist-able queue manager HOT 1
- Flaky test HOT 1
- Multiple Parallel Periodic jobs do not run in parallel HOT 2
- Can't persist jobs, Thread 1: "Invalid type in JSON write (__SwiftValue)" HOT 3
- A random crash HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swiftqueue.