SlideShare a Scribd company logo
1 of 52
Background Processing With WorkManager
Schedule background work easily
17.02.2022
BENEFITS
Pros of using WorkManager
Benefits
What’s good about WorkManager?
● Guaranteed. The work is guaranteed to execute.
● Work constraints. Specify best conditions for work. For example:
○ When the device is using Wi-FI.
○ The device is charging.
○ The device is idle.
○ Etc.
● Flexible scheduling. One-time and repeated work:
○ Can be delayed.
○ Minimum period between repeated work - 15 minutes.
● Retry policies. Provide retry policies in case there are some errors during execution.
● Work chaining. Chain multiple works in specific order with specific constraints.
● Works with RxJava and Coroutines.
● Built-in functionality for long work. Run in foreground and show notifications while the worker does the work.
● Integration with Hilt. Easily inject dependencies using only 3 annotations:
○ @HiltWorker, @AssistedInject, @Assisted
DISADVANTAGES
Cons of using WorkManager
Disadvantages
What’s not so good?
● Not precise. Repeated work is executed depending on various conditions and can be delayed by some time.
● Fast work doesn’t show notifications. The built-in functionality for notifications automatically removes the notification
once the job is done. If your work is quick there is a big chance the notification will not appear at all (possible to use
regular notification in this case).
INTRODUCTION
When to use WorkManager
When to use?
Types of Work and how to choose them
Note: Expedited work is available only in WorkManager 2.7.0+!
BASICS
Basics of WorkManager
Setup
Dependencies
Create Worker
Basic Worker
Extend Worker
Override doWork() and
return Result
Result
Types of Result
Result
retry
success
failure
The Work failed. It will not be restarted.
The Work failed. It will be restarted after
sometime.
The Work succeeded. If it’s periodic work,
it will be scheduled for next time.
Create Worker
Other types - Coroutine Worker
Extend
CoroutineWorker
Override suspend
doWork() and return
Result
Create Worker
Other types - RxWorker
Extend RxWorker
Override createWork()
and return
Single<Result>
Types of work requests
OneTimeWorkRequest | PeriodicWorkRequest
CREATING ONE TIME WORK
And specific features
One time work features
Specific features
● Chaining. Execute various works depending on different constraints.
● Expedited work. In case of a very important work that must be performed, possible to use expedited work. Features:
○ Importance: Expedited work suits tasks which are important to the user or are user-initiated.
○ Speed: Expedited work best fits short tasks that start immediately and complete within a few minutes.
○ Quotas: A system-level quota that limits foreground execution time determines whether an expedited job can
start.
○ Power Management: Power management restrictions ,such as Battery Saver and Doze, are less likely to affect
expedited work.
○ Latency: The system immediately executes expedited work, provided that the system's current workload
enables it to do so. This means they are latency sensitive and can't be scheduled for later execution.
Create OneTimeWorkRequest
Enqueue one work
Enqueue multiple works
Chaining
Add as much work as
you need!
Chaining - multiple one-time work
Work passed to WorkManager
Multiple one-time work
First Work succeeded | Second Work enqueued
Multiple one-time work
In case Result is retry(), the child works will wait until parent is success()!
Multiple one-time work
In case parent Work is failed all child Works are failed too!
Multiple one-time work
In case parent Work is cancelled all child Works are cancelled too!
Make work expedited
In case it’s very important!
Out of quotas?!
Choose what to in case there are no more quotas for your expedited work
OutOfQuotaPolicy
DROP_WORK_REQUEST
RUN_AS_NON_EXPEDITED_WORK_REQUEST
Run like non-expedited
Cancel the work
CREATING PERIODIC WORK
And specific features
Periodic work features
Specific features
● Additional parameters for the builder:
○ repeatInterval – The repeat interval in repeatIntervalTimeUnit units
○ repeatIntervalTimeUnit – The TimeUnit for repeatInterval
● Handling existing work with ExistingPeriodicWorkPolicy.
○ REPLACE - If there is existing pending (uncompleted) work with the same unique name, cancel and delete it.
Then, insert the newly-specified work.
○ KEEP - If there is existing pending (uncompleted) work with the same unique name, do nothing. Otherwise,
insert the newly-specified work.
Create PeriodicWorkRequest
Enqueue periodic work
CONSTRAINTS
Set the best conditions for work with work constraints
Constraints
Set the best time for work run
Note: DeviceIdle constraint requires min SDK version 23 (M)
WORK SCHEDULING
Set time and delay for work execution
Schedule work
Set delay and period time for your request
● One time work. For one time work you can specify initial delay:
○ .setInitialDelay(15L, TimeUnit.SECONDS)
● Periodic work. For periodic work you can specify initial delay and interval:
○ .setInitialDelay(15L, TimeUnit.SECONDS)
○ PeriodicWorkRequest.Builder(MyWorker::class.java,15L, TimeUnit.MINUTES)
ERROR HANDLING
Handle errors with retry policies
Handle errors
With BackOffCriteria
PASSING DATA
Pass data between multiple works
Pass data between your Work
Using Data
Note: You can pass only primitive types!
Pass data between your Work
Using InputMergers
InputMergers
ArrayCreatingInputMerger
OverwritingInputMerger
In case output from two works has same
name the last work will override the
value!
Works that have same output will be
stored in an array!
Pass data to the next Work
Pass output in our
Result.success(...)
Receive data in the next Work
NOTIFYING USER
Show foreground information to user
Notify user using ForegroundInfo
setForeground(...) makes the CoroutineWorker run in the context of a foreground android.app.Service
Call setForeground(...)
and pass
ForegroundInfo with
notification ID and
notification. Worker will
take care of the rest!
Note: If the Work is too fast there will be no notification! You can use regular way of showing notification in this case.
TRACKING WORK
Track the state of your work
Add tags
Tag your WorkRequest to track or even cancel Work later
Check work state
With WorkInfo
Contains lots of useful
information: Id, State,
Data, Tags, etc.
Various ways to get it!
HILT INTEGRATION
Integrate it with the recommended dependency injection library
Hilt set-up
In 3 steps
● Set-up Manifest.
● Set-up Application class.
● Use the following annotations to inject dependencies:
○ @HiltWorker - in Worker class.
○ @AssistedInject - instead of regular @Inject.
○ @Assisted - to inject Application Context and WorkerParameters
● Ready!
Manifest set-up
Disable automatic WorkManager initialization
Application class set-up
Extend Configuration.Provider and override getWorkManagerConfiguration()
Implement interface
Configuration.Provider
Inject
HiltWorkerFactory
Override
getWorkManagerConfi
guration() and set
HiltWorkerFactory
Worker set-up
@HiltWorker | @AssistedInject | @Assisted
UPCOMING MEETUP
Check out our event page
Stay tuned for what’s coming next!

More Related Content

Similar to Background Processing With Work Manager

Keeping code clean
Keeping code cleanKeeping code clean
Keeping code cleanBrett Child
 
Universal job embedding in recommendation (public ver.)
Universal job embedding in recommendation (public ver.)Universal job embedding in recommendation (public ver.)
Universal job embedding in recommendation (public ver.)Marsan Ma
 
2.1 Automation Nation: Keeping your Process Builders in Check
2.1 Automation Nation: Keeping your Process Builders in Check2.1 Automation Nation: Keeping your Process Builders in Check
2.1 Automation Nation: Keeping your Process Builders in CheckTargetX
 
Analysing in depth work manager
Analysing in depth work managerAnalysing in depth work manager
Analysing in depth work managerbhatnagar.gaurav83
 
Android scheduling.pptx
Android scheduling.pptxAndroid scheduling.pptx
Android scheduling.pptxZakiKhan66
 
Supervised embedding techniques in search ranking system
Supervised embedding techniques in search ranking systemSupervised embedding techniques in search ranking system
Supervised embedding techniques in search ranking systemMarsan Ma
 
Guidelines to understand durable functions with .net core, c# and stateful se...
Guidelines to understand durable functions with .net core, c# and stateful se...Guidelines to understand durable functions with .net core, c# and stateful se...
Guidelines to understand durable functions with .net core, c# and stateful se...Concetto Labs
 
What's new in WorkManager-Andri Suranta Ginting (Product Engineer-Gojek)
What's new in WorkManager-Andri Suranta Ginting (Product Engineer-Gojek)What's new in WorkManager-Andri Suranta Ginting (Product Engineer-Gojek)
What's new in WorkManager-Andri Suranta Ginting (Product Engineer-Gojek)DicodingEvent
 
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdf
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdfITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdf
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdfOrtus Solutions, Corp
 
Andrew - Job scheduler
Andrew - Job schedulerAndrew - Job scheduler
Andrew - Job schedulerrendra toro
 
KSCOPE 2015 - Improving Reliability, Rollouts, Upgrades/Migrations
KSCOPE 2015 - Improving Reliability, Rollouts, Upgrades/MigrationsKSCOPE 2015 - Improving Reliability, Rollouts, Upgrades/Migrations
KSCOPE 2015 - Improving Reliability, Rollouts, Upgrades/MigrationsCharles Beyer
 
OSMC 2012 | Shinken by Jean Gabès
OSMC 2012 | Shinken by Jean GabèsOSMC 2012 | Shinken by Jean Gabès
OSMC 2012 | Shinken by Jean GabèsNETWAYS
 
BDD Selenium for Agile Teams - User Stories
BDD Selenium for Agile Teams - User StoriesBDD Selenium for Agile Teams - User Stories
BDD Selenium for Agile Teams - User StoriesSauce Labs
 
Workflows via Event driven architecture
Workflows via Event driven architectureWorkflows via Event driven architecture
Workflows via Event driven architectureMilan Patel
 
Job Queues Overview
Job Queues OverviewJob Queues Overview
Job Queues Overviewjoeyrobert
 
8 Team Backrow Final Presentation
8 Team Backrow Final Presentation8 Team Backrow Final Presentation
8 Team Backrow Final PresentationKenedyThorne
 
Globant development week / React Redux Rorkshop
Globant development week / React Redux RorkshopGlobant development week / React Redux Rorkshop
Globant development week / React Redux RorkshopGlobant
 

Similar to Background Processing With Work Manager (20)

Keeping code clean
Keeping code cleanKeeping code clean
Keeping code clean
 
Universal job embedding in recommendation (public ver.)
Universal job embedding in recommendation (public ver.)Universal job embedding in recommendation (public ver.)
Universal job embedding in recommendation (public ver.)
 
Von neumann workers
Von neumann workersVon neumann workers
Von neumann workers
 
2.1 Automation Nation: Keeping your Process Builders in Check
2.1 Automation Nation: Keeping your Process Builders in Check2.1 Automation Nation: Keeping your Process Builders in Check
2.1 Automation Nation: Keeping your Process Builders in Check
 
Analysing in depth work manager
Analysing in depth work managerAnalysing in depth work manager
Analysing in depth work manager
 
Android scheduling.pptx
Android scheduling.pptxAndroid scheduling.pptx
Android scheduling.pptx
 
Supervised embedding techniques in search ranking system
Supervised embedding techniques in search ranking systemSupervised embedding techniques in search ranking system
Supervised embedding techniques in search ranking system
 
Guidelines to understand durable functions with .net core, c# and stateful se...
Guidelines to understand durable functions with .net core, c# and stateful se...Guidelines to understand durable functions with .net core, c# and stateful se...
Guidelines to understand durable functions with .net core, c# and stateful se...
 
What's new in WorkManager-Andri Suranta Ginting (Product Engineer-Gojek)
What's new in WorkManager-Andri Suranta Ginting (Product Engineer-Gojek)What's new in WorkManager-Andri Suranta Ginting (Product Engineer-Gojek)
What's new in WorkManager-Andri Suranta Ginting (Product Engineer-Gojek)
 
SPSDC 2013 Building Solutions using SharePoint Timer Jobs
SPSDC 2013 Building Solutions using SharePoint Timer JobsSPSDC 2013 Building Solutions using SharePoint Timer Jobs
SPSDC 2013 Building Solutions using SharePoint Timer Jobs
 
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdf
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdfITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdf
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdf
 
Andrew - Job scheduler
Andrew - Job schedulerAndrew - Job scheduler
Andrew - Job scheduler
 
KSCOPE 2015 - Improving Reliability, Rollouts, Upgrades/Migrations
KSCOPE 2015 - Improving Reliability, Rollouts, Upgrades/MigrationsKSCOPE 2015 - Improving Reliability, Rollouts, Upgrades/Migrations
KSCOPE 2015 - Improving Reliability, Rollouts, Upgrades/Migrations
 
OSMC 2012 | Shinken by Jean Gabès
OSMC 2012 | Shinken by Jean GabèsOSMC 2012 | Shinken by Jean Gabès
OSMC 2012 | Shinken by Jean Gabès
 
BDD Selenium for Agile Teams - User Stories
BDD Selenium for Agile Teams - User StoriesBDD Selenium for Agile Teams - User Stories
BDD Selenium for Agile Teams - User Stories
 
Workflows via Event driven architecture
Workflows via Event driven architectureWorkflows via Event driven architecture
Workflows via Event driven architecture
 
Feature toggling
Feature togglingFeature toggling
Feature toggling
 
Job Queues Overview
Job Queues OverviewJob Queues Overview
Job Queues Overview
 
8 Team Backrow Final Presentation
8 Team Backrow Final Presentation8 Team Backrow Final Presentation
8 Team Backrow Final Presentation
 
Globant development week / React Redux Rorkshop
Globant development week / React Redux RorkshopGlobant development week / React Redux Rorkshop
Globant development week / React Redux Rorkshop
 

More from Seven Peaks Speaks

Seven Peaks Speaks - Compose Screenshot Testing Made Easy
Seven Peaks Speaks - Compose Screenshot Testing Made EasySeven Peaks Speaks - Compose Screenshot Testing Made Easy
Seven Peaks Speaks - Compose Screenshot Testing Made EasySeven Peaks Speaks
 
Seven Peaks Speaks - Android Jetpack Compose Animation
Seven Peaks Speaks - Android Jetpack Compose AnimationSeven Peaks Speaks - Android Jetpack Compose Animation
Seven Peaks Speaks - Android Jetpack Compose AnimationSeven Peaks Speaks
 
Seven Peaks Speaks - Compose Navigation
Seven Peaks Speaks - Compose NavigationSeven Peaks Speaks - Compose Navigation
Seven Peaks Speaks - Compose NavigationSeven Peaks Speaks
 
How to Get Better Performance Out of Your App
How to Get Better Performance Out of Your AppHow to Get Better Performance Out of Your App
How to Get Better Performance Out of Your AppSeven Peaks Speaks
 
Secure Development of Azure Function
Secure Development of Azure FunctionSecure Development of Azure Function
Secure Development of Azure FunctionSeven Peaks Speaks
 
Develop Security & Compliances in Azure
Develop Security & Compliances in AzureDevelop Security & Compliances in Azure
Develop Security & Compliances in AzureSeven Peaks Speaks
 
Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)Seven Peaks Speaks
 
Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)Seven Peaks Speaks
 
Delivering react app with confidence: Testing Pyramid
Delivering react app with confidence: Testing PyramidDelivering react app with confidence: Testing Pyramid
Delivering react app with confidence: Testing PyramidSeven Peaks Speaks
 
Getting hooked on performance and clean code
Getting hooked on performance and clean codeGetting hooked on performance and clean code
Getting hooked on performance and clean codeSeven Peaks Speaks
 
Establishing secure Biometric authentication in Android
Establishing secure Biometric authentication in AndroidEstablishing secure Biometric authentication in Android
Establishing secure Biometric authentication in AndroidSeven Peaks Speaks
 
Utilizing kotlin flows in an android application
Utilizing kotlin flows in an android applicationUtilizing kotlin flows in an android application
Utilizing kotlin flows in an android applicationSeven Peaks Speaks
 
Continuously deploy a containerized app to “Azure App Service”
Continuously deploy a containerized app to “Azure App Service”Continuously deploy a containerized app to “Azure App Service”
Continuously deploy a containerized app to “Azure App Service”Seven Peaks Speaks
 

More from Seven Peaks Speaks (20)

BKK Web: Working with SEO
BKK Web: Working with SEOBKK Web: Working with SEO
BKK Web: Working with SEO
 
Seven Peaks Speaks - Compose Screenshot Testing Made Easy
Seven Peaks Speaks - Compose Screenshot Testing Made EasySeven Peaks Speaks - Compose Screenshot Testing Made Easy
Seven Peaks Speaks - Compose Screenshot Testing Made Easy
 
Seven Peaks Speaks - Android Jetpack Compose Animation
Seven Peaks Speaks - Android Jetpack Compose AnimationSeven Peaks Speaks - Android Jetpack Compose Animation
Seven Peaks Speaks - Android Jetpack Compose Animation
 
Seven Peaks Speaks - Compose Navigation
Seven Peaks Speaks - Compose NavigationSeven Peaks Speaks - Compose Navigation
Seven Peaks Speaks - Compose Navigation
 
How to Get Better Performance Out of Your App
How to Get Better Performance Out of Your AppHow to Get Better Performance Out of Your App
How to Get Better Performance Out of Your App
 
RxSubject And Operators
RxSubject And OperatorsRxSubject And Operators
RxSubject And Operators
 
Concurrency in Swift
Concurrency in SwiftConcurrency in Swift
Concurrency in Swift
 
DevSecOps on Azure
DevSecOps on AzureDevSecOps on Azure
DevSecOps on Azure
 
Secure Development of Azure Function
Secure Development of Azure FunctionSecure Development of Azure Function
Secure Development of Azure Function
 
Develop Security & Compliances in Azure
Develop Security & Compliances in AzureDevelop Security & Compliances in Azure
Develop Security & Compliances in Azure
 
Effective Lists Management
Effective Lists ManagementEffective Lists Management
Effective Lists Management
 
Layout Preview Tooling
Layout Preview ToolingLayout Preview Tooling
Layout Preview Tooling
 
Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
 
Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
 
Delivering react app with confidence: Testing Pyramid
Delivering react app with confidence: Testing PyramidDelivering react app with confidence: Testing Pyramid
Delivering react app with confidence: Testing Pyramid
 
React context
React context  React context
React context
 
Getting hooked on performance and clean code
Getting hooked on performance and clean codeGetting hooked on performance and clean code
Getting hooked on performance and clean code
 
Establishing secure Biometric authentication in Android
Establishing secure Biometric authentication in AndroidEstablishing secure Biometric authentication in Android
Establishing secure Biometric authentication in Android
 
Utilizing kotlin flows in an android application
Utilizing kotlin flows in an android applicationUtilizing kotlin flows in an android application
Utilizing kotlin flows in an android application
 
Continuously deploy a containerized app to “Azure App Service”
Continuously deploy a containerized app to “Azure App Service”Continuously deploy a containerized app to “Azure App Service”
Continuously deploy a containerized app to “Azure App Service”
 

Recently uploaded

Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...Abortion Clinic
 
Weeding your micro service landscape.pdf
Weeding your micro service landscape.pdfWeeding your micro service landscape.pdf
Weeding your micro service landscape.pdftimtebeek1
 
Your Ultimate Web Studio for Streaming Anywhere | Evmux
Your Ultimate Web Studio for Streaming Anywhere | EvmuxYour Ultimate Web Studio for Streaming Anywhere | Evmux
Your Ultimate Web Studio for Streaming Anywhere | Evmuxevmux96
 
Encryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key ConceptsEncryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key Conceptsthomashtkim
 
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Andreas Granig
 
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
Auto Affiliate  AI Earns First Commission in 3 Hours..pdfAuto Affiliate  AI Earns First Commission in 3 Hours..pdf
Auto Affiliate AI Earns First Commission in 3 Hours..pdfSelfMade bd
 
Test Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdfTest Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdfkalichargn70th171
 
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024SimonedeGijt
 
Community is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletCommunity is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletAndrea Goulet
 
[GRCPP] Introduction to concepts (C++20)
[GRCPP] Introduction to concepts (C++20)[GRCPP] Introduction to concepts (C++20)
[GRCPP] Introduction to concepts (C++20)Dimitrios Platis
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAShane Coughlan
 
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypseTomasz Kowalczewski
 
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
Workshop -  Architecting Innovative Graph Applications- GraphSummit MilanWorkshop -  Architecting Innovative Graph Applications- GraphSummit Milan
Workshop - Architecting Innovative Graph Applications- GraphSummit MilanNeo4j
 
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...Lisi Hocke
 
Microsoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMicrosoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMarkus Moeller
 
GraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with GraphGraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with GraphNeo4j
 
Lessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdfLessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdfSrushith Repakula
 

Recently uploaded (20)

Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
 
Weeding your micro service landscape.pdf
Weeding your micro service landscape.pdfWeeding your micro service landscape.pdf
Weeding your micro service landscape.pdf
 
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
 
Your Ultimate Web Studio for Streaming Anywhere | Evmux
Your Ultimate Web Studio for Streaming Anywhere | EvmuxYour Ultimate Web Studio for Streaming Anywhere | Evmux
Your Ultimate Web Studio for Streaming Anywhere | Evmux
 
Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...
Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...
Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...
 
Encryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key ConceptsEncryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key Concepts
 
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
 
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
 
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
Auto Affiliate  AI Earns First Commission in 3 Hours..pdfAuto Affiliate  AI Earns First Commission in 3 Hours..pdf
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
 
Test Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdfTest Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdf
 
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
 
Community is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletCommunity is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea Goulet
 
[GRCPP] Introduction to concepts (C++20)
[GRCPP] Introduction to concepts (C++20)[GRCPP] Introduction to concepts (C++20)
[GRCPP] Introduction to concepts (C++20)
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
 
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
 
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
Workshop -  Architecting Innovative Graph Applications- GraphSummit MilanWorkshop -  Architecting Innovative Graph Applications- GraphSummit Milan
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
 
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
 
Microsoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMicrosoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdf
 
GraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with GraphGraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with Graph
 
Lessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdfLessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdf
 

Background Processing With Work Manager

  • 1. Background Processing With WorkManager Schedule background work easily 17.02.2022
  • 3. Benefits What’s good about WorkManager? ● Guaranteed. The work is guaranteed to execute. ● Work constraints. Specify best conditions for work. For example: ○ When the device is using Wi-FI. ○ The device is charging. ○ The device is idle. ○ Etc. ● Flexible scheduling. One-time and repeated work: ○ Can be delayed. ○ Minimum period between repeated work - 15 minutes. ● Retry policies. Provide retry policies in case there are some errors during execution. ● Work chaining. Chain multiple works in specific order with specific constraints. ● Works with RxJava and Coroutines. ● Built-in functionality for long work. Run in foreground and show notifications while the worker does the work. ● Integration with Hilt. Easily inject dependencies using only 3 annotations: ○ @HiltWorker, @AssistedInject, @Assisted
  • 5. Disadvantages What’s not so good? ● Not precise. Repeated work is executed depending on various conditions and can be delayed by some time. ● Fast work doesn’t show notifications. The built-in functionality for notifications automatically removes the notification once the job is done. If your work is quick there is a big chance the notification will not appear at all (possible to use regular notification in this case).
  • 7. When to use? Types of Work and how to choose them Note: Expedited work is available only in WorkManager 2.7.0+!
  • 10. Create Worker Basic Worker Extend Worker Override doWork() and return Result
  • 11. Result Types of Result Result retry success failure The Work failed. It will not be restarted. The Work failed. It will be restarted after sometime. The Work succeeded. If it’s periodic work, it will be scheduled for next time.
  • 12. Create Worker Other types - Coroutine Worker Extend CoroutineWorker Override suspend doWork() and return Result
  • 13. Create Worker Other types - RxWorker Extend RxWorker Override createWork() and return Single<Result>
  • 14. Types of work requests OneTimeWorkRequest | PeriodicWorkRequest
  • 15. CREATING ONE TIME WORK And specific features
  • 16. One time work features Specific features ● Chaining. Execute various works depending on different constraints. ● Expedited work. In case of a very important work that must be performed, possible to use expedited work. Features: ○ Importance: Expedited work suits tasks which are important to the user or are user-initiated. ○ Speed: Expedited work best fits short tasks that start immediately and complete within a few minutes. ○ Quotas: A system-level quota that limits foreground execution time determines whether an expedited job can start. ○ Power Management: Power management restrictions ,such as Battery Saver and Doze, are less likely to affect expedited work. ○ Latency: The system immediately executes expedited work, provided that the system's current workload enables it to do so. This means they are latency sensitive and can't be scheduled for later execution.
  • 19. Enqueue multiple works Chaining Add as much work as you need!
  • 20. Chaining - multiple one-time work Work passed to WorkManager
  • 21. Multiple one-time work First Work succeeded | Second Work enqueued
  • 22. Multiple one-time work In case Result is retry(), the child works will wait until parent is success()!
  • 23. Multiple one-time work In case parent Work is failed all child Works are failed too!
  • 24. Multiple one-time work In case parent Work is cancelled all child Works are cancelled too!
  • 25. Make work expedited In case it’s very important!
  • 26. Out of quotas?! Choose what to in case there are no more quotas for your expedited work OutOfQuotaPolicy DROP_WORK_REQUEST RUN_AS_NON_EXPEDITED_WORK_REQUEST Run like non-expedited Cancel the work
  • 27. CREATING PERIODIC WORK And specific features
  • 28. Periodic work features Specific features ● Additional parameters for the builder: ○ repeatInterval – The repeat interval in repeatIntervalTimeUnit units ○ repeatIntervalTimeUnit – The TimeUnit for repeatInterval ● Handling existing work with ExistingPeriodicWorkPolicy. ○ REPLACE - If there is existing pending (uncompleted) work with the same unique name, cancel and delete it. Then, insert the newly-specified work. ○ KEEP - If there is existing pending (uncompleted) work with the same unique name, do nothing. Otherwise, insert the newly-specified work.
  • 31. CONSTRAINTS Set the best conditions for work with work constraints
  • 32. Constraints Set the best time for work run Note: DeviceIdle constraint requires min SDK version 23 (M)
  • 33. WORK SCHEDULING Set time and delay for work execution
  • 34. Schedule work Set delay and period time for your request ● One time work. For one time work you can specify initial delay: ○ .setInitialDelay(15L, TimeUnit.SECONDS) ● Periodic work. For periodic work you can specify initial delay and interval: ○ .setInitialDelay(15L, TimeUnit.SECONDS) ○ PeriodicWorkRequest.Builder(MyWorker::class.java,15L, TimeUnit.MINUTES)
  • 35. ERROR HANDLING Handle errors with retry policies
  • 37. PASSING DATA Pass data between multiple works
  • 38. Pass data between your Work Using Data Note: You can pass only primitive types!
  • 39. Pass data between your Work Using InputMergers InputMergers ArrayCreatingInputMerger OverwritingInputMerger In case output from two works has same name the last work will override the value! Works that have same output will be stored in an array!
  • 40. Pass data to the next Work Pass output in our Result.success(...)
  • 41. Receive data in the next Work
  • 42. NOTIFYING USER Show foreground information to user
  • 43. Notify user using ForegroundInfo setForeground(...) makes the CoroutineWorker run in the context of a foreground android.app.Service Call setForeground(...) and pass ForegroundInfo with notification ID and notification. Worker will take care of the rest! Note: If the Work is too fast there will be no notification! You can use regular way of showing notification in this case.
  • 44. TRACKING WORK Track the state of your work
  • 45. Add tags Tag your WorkRequest to track or even cancel Work later
  • 46. Check work state With WorkInfo Contains lots of useful information: Id, State, Data, Tags, etc. Various ways to get it!
  • 47. HILT INTEGRATION Integrate it with the recommended dependency injection library
  • 48. Hilt set-up In 3 steps ● Set-up Manifest. ● Set-up Application class. ● Use the following annotations to inject dependencies: ○ @HiltWorker - in Worker class. ○ @AssistedInject - instead of regular @Inject. ○ @Assisted - to inject Application Context and WorkerParameters ● Ready!
  • 49. Manifest set-up Disable automatic WorkManager initialization
  • 50. Application class set-up Extend Configuration.Provider and override getWorkManagerConfiguration() Implement interface Configuration.Provider Inject HiltWorkerFactory Override getWorkManagerConfi guration() and set HiltWorkerFactory
  • 51. Worker set-up @HiltWorker | @AssistedInject | @Assisted
  • 52. UPCOMING MEETUP Check out our event page Stay tuned for what’s coming next!