#1 이전 글
위 게시글의 완성된 앱을 일부 수정해서, 복수의 Worker가 순서를 지키며 실행되게 만들어본다.
#2 Work Chaining
서버에 이미지를 전송하는 경우를 예로 들면, 먼저 해당 이미지를 filtering하고, compress하고, upload해야 한다. 이 일련의 작업들은 List 자료구조처럼 순서가 존재하며, 이렇게 순서가 부여된 작업의 집합을 만드는 것을 Work Chaining(연쇄)이라고 부른다.
#3 코드 수정
#3-1 OtherWorker.kt 생성
...
class OtherWorker(context: Context, params: WorkerParameters) : Worker(context, params) {
...
}
UploadWorker.kt와 파일 이름 및 클래스 이름을 제외하고 모두 동일한 Worker 클래스를 만든다.
#3-2 AnotherWorker.kt 생성
...
class AnotherWorker(context: Context, params: WorkerParameters) : Worker(context, params) {
...
}
마찬가지로, UploadWorker.kt와 파일 이름 및 클래스 이름을 제외하고 모두 동일한 Worker 클래스를 만든다.
#3-3 MainActivity - setOneTimeWorkRequest()
...
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
...
}
private fun setOneTimeWorkRequest() {
// WorkRequest 객체 만들기
val uploadRequest = OneTimeWorkRequest
.Builder(UploadWorker::class.java)
.build()
val otherWorker = OneTimeWorkRequest
.Builder(OtherWorker::class.java)
.build()
val anotherWorker = OneTimeWorkRequest
.Builder(AnotherWorker::class.java)
.build()
// WorkManager 객체의 작업 큐(Job queue)에 WorkRequest 등록
workManager
.beginWith(otherWorker)
.then(anotherWorker)
.then(uploadRequest)
.enqueue()
// WorkInfo는 작업에 대한 정보를 담은 객체.
// WorkManager.getWorkInfoByIdLiveData()는 LiveData<WorkInfo>를 반환.
...
}
private fun setPeriodicWorkRequest() {
...
}
}
#3-4 MainActivity - setOneTimeWorkRequest()
...
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
...
}
private fun setOneTimeWorkRequest() {
...
}
private fun setPeriodicWorkRequest() {
// 'Worker 체인 개시'용 Worker 만들기
val chainInitiationWorker = PeriodicWorkRequest
.Builder(ChainInitiationWorker::class.java, 15, TimeUnit.MINUTES) // 안드로이드에서 허용하는 PeriodicWorkRequest의 최소 주기는 15분이다.
.build()
// WorkManager 객체의 작업 큐(Job queue)에 WorkRequest 등록
workManager.enqueue(chainInitiationWorker)
// WorkInfo는 작업에 대한 정보를 담은 객체.
// WorkManager.getWorkInfoByIdLiveData()는 LiveData<WorkInfo>를 반환.
...
}
}
PeriodicWorkRequest에서는 Work Chaining을 할 수 없다. Work Chaining 때문에 실행 주기의 타이밍이 어긋나고, 이전 작업이 완료될 때까지 대기하느라 그 다음 주기가 돌아와버리고 결국 작업의 중복 실행이 야기될 수 있기 때문에 직접적인 구현이 막혀있다. 하지만, 이를 우회할 수 있다. 바로 Worker 클래스 하나를 PeriodicWorkRequest에 넣고, 해당 Worker 클래스 내부에서 Work Chaining을 하는 것이다. 아래 코드를 보자.
#3-5 ChainInitiationWorker.kt
...
class ChainInitiationWorker(context: Context, params: WorkerParameters) : Worker(context, params) {
override fun doWork(): Result {
try {
val workManager = WorkManager.getInstance(applicationContext)
// WorkRequest 객체 만들기
val downloadRequest = OneTimeWorkRequest
.Builder(DownloadWorker::class.java)
.build()
val otherWorker = OneTimeWorkRequest
.Builder(OtherWorker::class.java)
.build()
val anotherWorker = OneTimeWorkRequest
.Builder(AnotherWorker::class.java)
.build()
Log.i(...)
workManager
.beginWith(otherWorker)
.then(anotherWorker)
.then(downloadRequest)
.enqueue()
Log.i(...)
return Result.success()
} catch (e: Exception) {
return Result.failure()
}
}
private fun getNowTime(): String {
...
}
}
UploadWorker.kt의 코드를 기반으로 하고, 거기에 WorkRequest 객체 생성 및 WorkManager의 작업 큐에 등록하는 코드를 추가했다.
#4 작동 확인
#4-1 'One Time Request' 버튼을 클릭했을 때의 로그 메시지
(MainActivity) UploadWorker's state: BLOCKED
(OtherWorker) Started at 2024/06/17 10:09:03
(OtherWorker) Progress: 0/100
(OtherWorker) Progress: 1/100
(OtherWorker) Progress: 2/100
(OtherWorker) Progress: 3/100
(OtherWorker) Progress: 4/100
(OtherWorker) Progress: 5/100
(OtherWorker) Progress: 6/100
(OtherWorker) Progress: 7/100
(OtherWorker) Progress: 8/100
(OtherWorker) Progress: 9/100
(OtherWorker) Progress: 10/100
(OtherWorker) Progress: 11/100
(OtherWorker) Progress: 12/100
(OtherWorker) Progress: 13/100
(OtherWorker) Progress: 14/100
(OtherWorker) Progress: 15/100
(OtherWorker) Progress: 16/100
(OtherWorker) Progress: 17/100
(OtherWorker) Progress: 18/100
(OtherWorker) Progress: 19/100
(OtherWorker) Progress: 20/100
(OtherWorker) Progress: 21/100
(OtherWorker) Progress: 22/100
(OtherWorker) Progress: 23/100
(OtherWorker) Progress: 24/100
(OtherWorker) Progress: 25/100
(OtherWorker) Progress: 26/100
(OtherWorker) Progress: 27/100
(OtherWorker) Progress: 28/100
(OtherWorker) Progress: 29/100
(OtherWorker) Progress: 30/100
(OtherWorker) Progress: 31/100
(OtherWorker) Progress: 32/100
(OtherWorker) Progress: 33/100
(OtherWorker) Progress: 34/100
(OtherWorker) Progress: 35/100
(OtherWorker) Progress: 36/100
(OtherWorker) Progress: 37/100
(OtherWorker) Progress: 38/100
(OtherWorker) Progress: 39/100
(OtherWorker) Progress: 40/100
(OtherWorker) Progress: 41/100
(OtherWorker) Progress: 42/100
(OtherWorker) Progress: 43/100
(OtherWorker) Progress: 44/100
(OtherWorker) Progress: 45/100
(OtherWorker) Progress: 46/100
(OtherWorker) Progress: 47/100
(OtherWorker) Progress: 48/100
(OtherWorker) Progress: 49/100
(OtherWorker) Progress: 50/100
(OtherWorker) Progress: 51/100
(OtherWorker) Progress: 52/100
(OtherWorker) Progress: 53/100
(OtherWorker) Progress: 54/100
(OtherWorker) Progress: 55/100
(OtherWorker) Progress: 56/100
(OtherWorker) Progress: 57/100
(OtherWorker) Progress: 58/100
(OtherWorker) Progress: 59/100
(OtherWorker) Progress: 60/100
(OtherWorker) Progress: 61/100
(OtherWorker) Progress: 62/100
(OtherWorker) Progress: 63/100
(OtherWorker) Progress: 64/100
(OtherWorker) Progress: 65/100
(OtherWorker) Progress: 66/100
(OtherWorker) Progress: 67/100
(OtherWorker) Progress: 68/100
(OtherWorker) Progress: 69/100
(OtherWorker) Progress: 70/100
(OtherWorker) Progress: 71/100
(OtherWorker) Progress: 72/100
(OtherWorker) Progress: 73/100
(OtherWorker) Progress: 74/100
(OtherWorker) Progress: 75/100
(OtherWorker) Progress: 76/100
(OtherWorker) Progress: 77/100
(OtherWorker) Progress: 78/100
(OtherWorker) Progress: 79/100
(OtherWorker) Progress: 80/100
(OtherWorker) Progress: 81/100
(OtherWorker) Progress: 82/100
(OtherWorker) Progress: 83/100
(OtherWorker) Progress: 84/100
(OtherWorker) Progress: 85/100
(OtherWorker) Progress: 86/100
(OtherWorker) Progress: 87/100
(OtherWorker) Progress: 88/100
(OtherWorker) Progress: 89/100
(OtherWorker) Progress: 90/100
(OtherWorker) Progress: 91/100
(OtherWorker) Progress: 92/100
(OtherWorker) Progress: 93/100
(OtherWorker) Progress: 94/100
(OtherWorker) Progress: 95/100
(OtherWorker) Progress: 96/100
(OtherWorker) Progress: 97/100
(OtherWorker) Progress: 98/100
(OtherWorker) Progress: 99/100
(OtherWorker) Progress: 100/100
(OtherWorker) Finished at 2024/06/17 10:09:03
(AnotherWorker) Started at 2024/06/17 10:09:03
(AnotherWorker) Progress: 0/100
(AnotherWorker) Progress: 1/100
(AnotherWorker) Progress: 2/100
(AnotherWorker) Progress: 3/100
(AnotherWorker) Progress: 4/100
(AnotherWorker) Progress: 5/100
(AnotherWorker) Progress: 6/100
(AnotherWorker) Progress: 7/100
(AnotherWorker) Progress: 8/100
(AnotherWorker) Progress: 9/100
(AnotherWorker) Progress: 10/100
(AnotherWorker) Progress: 11/100
(AnotherWorker) Progress: 12/100
(AnotherWorker) Progress: 13/100
(AnotherWorker) Progress: 14/100
(AnotherWorker) Progress: 15/100
(AnotherWorker) Progress: 16/100
(AnotherWorker) Progress: 17/100
(AnotherWorker) Progress: 18/100
(AnotherWorker) Progress: 19/100
(AnotherWorker) Progress: 20/100
(AnotherWorker) Progress: 21/100
(AnotherWorker) Progress: 22/100
(AnotherWorker) Progress: 23/100
(AnotherWorker) Progress: 24/100
(AnotherWorker) Progress: 25/100
(AnotherWorker) Progress: 26/100
(AnotherWorker) Progress: 27/100
(AnotherWorker) Progress: 28/100
(AnotherWorker) Progress: 29/100
(AnotherWorker) Progress: 30/100
(AnotherWorker) Progress: 31/100
(AnotherWorker) Progress: 32/100
(AnotherWorker) Progress: 33/100
(AnotherWorker) Progress: 34/100
(AnotherWorker) Progress: 35/100
(AnotherWorker) Progress: 36/100
(AnotherWorker) Progress: 37/100
(AnotherWorker) Progress: 38/100
(AnotherWorker) Progress: 39/100
(AnotherWorker) Progress: 40/100
(AnotherWorker) Progress: 41/100
(AnotherWorker) Progress: 42/100
(AnotherWorker) Progress: 43/100
(AnotherWorker) Progress: 44/100
(AnotherWorker) Progress: 45/100
(AnotherWorker) Progress: 46/100
(AnotherWorker) Progress: 47/100
(AnotherWorker) Progress: 48/100
(AnotherWorker) Progress: 49/100
(AnotherWorker) Progress: 50/100
(AnotherWorker) Progress: 51/100
(AnotherWorker) Progress: 52/100
(AnotherWorker) Progress: 53/100
(AnotherWorker) Progress: 54/100
(AnotherWorker) Progress: 55/100
(AnotherWorker) Progress: 56/100
(AnotherWorker) Progress: 57/100
(AnotherWorker) Progress: 58/100
(AnotherWorker) Progress: 59/100
(AnotherWorker) Progress: 60/100
(AnotherWorker) Progress: 61/100
(AnotherWorker) Progress: 62/100
(AnotherWorker) Progress: 63/100
(AnotherWorker) Progress: 64/100
(AnotherWorker) Progress: 65/100
(AnotherWorker) Progress: 66/100
(AnotherWorker) Progress: 67/100
(AnotherWorker) Progress: 68/100
(AnotherWorker) Progress: 69/100
(AnotherWorker) Progress: 70/100
(AnotherWorker) Progress: 71/100
(AnotherWorker) Progress: 72/100
(AnotherWorker) Progress: 73/100
(AnotherWorker) Progress: 74/100
(AnotherWorker) Progress: 75/100
(AnotherWorker) Progress: 76/100
(AnotherWorker) Progress: 77/100
(AnotherWorker) Progress: 78/100
(AnotherWorker) Progress: 79/100
(AnotherWorker) Progress: 80/100
(AnotherWorker) Progress: 81/100
(AnotherWorker) Progress: 82/100
(AnotherWorker) Progress: 83/100
(AnotherWorker) Progress: 84/100
(AnotherWorker) Progress: 85/100
(AnotherWorker) Progress: 86/100
(AnotherWorker) Progress: 87/100
(AnotherWorker) Progress: 88/100
(AnotherWorker) Progress: 89/100
(AnotherWorker) Progress: 90/100
(AnotherWorker) Progress: 91/100
(AnotherWorker) Progress: 92/100
(AnotherWorker) Progress: 93/100
(AnotherWorker) Progress: 94/100
(AnotherWorker) Progress: 95/100
(AnotherWorker) Progress: 96/100
(AnotherWorker) Progress: 97/100
(AnotherWorker) Progress: 98/100
(AnotherWorker) Progress: 99/100
(AnotherWorker) Progress: 100/100
(AnotherWorker) Finished at 2024/06/17 10:09:03
(MainActivity) UploadWorker's state: ENQUEUED
(UploadWorker) Started at 2024/06/17 10:09:03
(UploadWorker) Progress: 0/100
(UploadWorker) Progress: 1/100
(UploadWorker) Progress: 2/100
(UploadWorker) Progress: 3/100
(UploadWorker) Progress: 4/100
(UploadWorker) Progress: 5/100
(UploadWorker) Progress: 6/100
(UploadWorker) Progress: 7/100
(UploadWorker) Progress: 8/100
(UploadWorker) Progress: 9/100
(UploadWorker) Progress: 10/100
(UploadWorker) Progress: 11/100
(UploadWorker) Progress: 12/100
(MainActivity) UploadWorker's state: RUNNING
(UploadWorker) Progress: 13/100
(UploadWorker) Progress: 14/100
(UploadWorker) Progress: 15/100
(UploadWorker) Progress: 16/100
(UploadWorker) Progress: 17/100
(UploadWorker) Progress: 18/100
(UploadWorker) Progress: 19/100
(UploadWorker) Progress: 20/100
(UploadWorker) Progress: 21/100
(UploadWorker) Progress: 22/100
(UploadWorker) Progress: 23/100
(UploadWorker) Progress: 24/100
(UploadWorker) Progress: 25/100
(UploadWorker) Progress: 26/100
(UploadWorker) Progress: 27/100
(UploadWorker) Progress: 28/100
(UploadWorker) Progress: 29/100
(UploadWorker) Progress: 30/100
(UploadWorker) Progress: 31/100
(UploadWorker) Progress: 32/100
(UploadWorker) Progress: 33/100
(UploadWorker) Progress: 34/100
(UploadWorker) Progress: 35/100
(UploadWorker) Progress: 36/100
(UploadWorker) Progress: 37/100
(UploadWorker) Progress: 38/100
(UploadWorker) Progress: 39/100
(UploadWorker) Progress: 40/100
(UploadWorker) Progress: 41/100
(UploadWorker) Progress: 42/100
(UploadWorker) Progress: 43/100
(UploadWorker) Progress: 44/100
(UploadWorker) Progress: 45/100
(UploadWorker) Progress: 46/100
(UploadWorker) Progress: 47/100
(UploadWorker) Progress: 48/100
(UploadWorker) Progress: 49/100
(UploadWorker) Progress: 50/100
(UploadWorker) Progress: 51/100
(UploadWorker) Progress: 52/100
(UploadWorker) Progress: 53/100
(UploadWorker) Progress: 54/100
(UploadWorker) Progress: 55/100
(UploadWorker) Progress: 56/100
(UploadWorker) Progress: 57/100
(UploadWorker) Progress: 58/100
(UploadWorker) Progress: 59/100
(UploadWorker) Progress: 60/100
(UploadWorker) Progress: 61/100
(UploadWorker) Progress: 62/100
(UploadWorker) Progress: 63/100
(UploadWorker) Progress: 64/100
(UploadWorker) Progress: 65/100
(UploadWorker) Progress: 66/100
(UploadWorker) Progress: 67/100
(UploadWorker) Progress: 68/100
(UploadWorker) Progress: 69/100
(UploadWorker) Progress: 70/100
(UploadWorker) Progress: 71/100
(UploadWorker) Progress: 72/100
(UploadWorker) Progress: 73/100
(UploadWorker) Progress: 74/100
(UploadWorker) Progress: 75/100
(UploadWorker) Progress: 76/100
(UploadWorker) Progress: 77/100
(UploadWorker) Progress: 78/100
(UploadWorker) Progress: 79/100
(UploadWorker) Progress: 80/100
(UploadWorker) Progress: 81/100
(UploadWorker) Progress: 82/100
(UploadWorker) Progress: 83/100
(UploadWorker) Progress: 84/100
(UploadWorker) Progress: 85/100
(UploadWorker) Progress: 86/100
(UploadWorker) Progress: 87/100
(UploadWorker) Progress: 88/100
(UploadWorker) Progress: 89/100
(UploadWorker) Progress: 90/100
(UploadWorker) Progress: 91/100
(UploadWorker) Progress: 92/100
(UploadWorker) Progress: 93/100
(UploadWorker) Progress: 94/100
(UploadWorker) Progress: 95/100
(UploadWorker) Progress: 96/100
(UploadWorker) Progress: 97/100
(UploadWorker) Progress: 98/100
(UploadWorker) Progress: 99/100
(UploadWorker) Progress: 100/100
(UploadWorker) Finished at 2024/06/17 10:09:03
(MainActivity) UploadWorker's state: SUCCEEDED
UploadWorker의 상태가 BLOCKED인 것을 확인할 수 있다. BLOCKED는 B 작업의 선행 작업 A가 완료되지 않아서 순서 상 A에게 종속된(= 뒤에 있는) B의 실행이 유예된 상태를 의미한다 (이 게시글의 #3 참조).
#4-2 'Periodic Request' 버튼을 클릭했을 때의 로그 메시지
(MainActivity) ChainInitiationWorker's state: ENQUEUED
(ChainInitiationWorker) Started at 2024/06/17 10:11:41
(ChainInitiationWorker) Finished at 2024/06/17 10:11:41
(MainActivity) ChainInitiationWorker's state: RUNNING
(OtherWorker) Started at 2024/06/17 10:11:41
(OtherWorker) Progress: 0/100
(OtherWorker) Progress: 1/100
(OtherWorker) Progress: 2/100
(OtherWorker) Progress: 3/100
(OtherWorker) Progress: 4/100
(OtherWorker) Progress: 5/100
(OtherWorker) Progress: 6/100
(OtherWorker) Progress: 7/100
(OtherWorker) Progress: 8/100
(OtherWorker) Progress: 9/100
(OtherWorker) Progress: 10/100
(OtherWorker) Progress: 11/100
(MainActivity) ChainInitiationWorker's state: ENQUEUED
(OtherWorker) Progress: 12/100
(OtherWorker) Progress: 13/100
(OtherWorker) Progress: 14/100
(OtherWorker) Progress: 15/100
(OtherWorker) Progress: 16/100
(OtherWorker) Progress: 17/100
(OtherWorker) Progress: 18/100
(OtherWorker) Progress: 19/100
(OtherWorker) Progress: 20/100
(OtherWorker) Progress: 21/100
(OtherWorker) Progress: 22/100
(OtherWorker) Progress: 23/100
(OtherWorker) Progress: 24/100
(OtherWorker) Progress: 25/100
(OtherWorker) Progress: 26/100
(OtherWorker) Progress: 27/100
(OtherWorker) Progress: 28/100
(OtherWorker) Progress: 29/100
(OtherWorker) Progress: 30/100
(OtherWorker) Progress: 31/100
(OtherWorker) Progress: 32/100
(OtherWorker) Progress: 33/100
(OtherWorker) Progress: 34/100
(OtherWorker) Progress: 35/100
(OtherWorker) Progress: 36/100
(OtherWorker) Progress: 37/100
(OtherWorker) Progress: 38/100
(OtherWorker) Progress: 39/100
(OtherWorker) Progress: 40/100
(OtherWorker) Progress: 41/100
(OtherWorker) Progress: 42/100
(OtherWorker) Progress: 43/100
(OtherWorker) Progress: 44/100
(OtherWorker) Progress: 45/100
(OtherWorker) Progress: 46/100
(OtherWorker) Progress: 47/100
(OtherWorker) Progress: 48/100
(OtherWorker) Progress: 49/100
(OtherWorker) Progress: 50/100
(OtherWorker) Progress: 51/100
(OtherWorker) Progress: 52/100
(OtherWorker) Progress: 53/100
(OtherWorker) Progress: 54/100
(OtherWorker) Progress: 55/100
(OtherWorker) Progress: 56/100
(OtherWorker) Progress: 57/100
(OtherWorker) Progress: 58/100
(OtherWorker) Progress: 59/100
(OtherWorker) Progress: 60/100
(OtherWorker) Progress: 61/100
(OtherWorker) Progress: 62/100
(OtherWorker) Progress: 63/100
(OtherWorker) Progress: 64/100
(OtherWorker) Progress: 65/100
(OtherWorker) Progress: 66/100
(OtherWorker) Progress: 67/100
(OtherWorker) Progress: 68/100
(OtherWorker) Progress: 69/100
(OtherWorker) Progress: 70/100
(OtherWorker) Progress: 71/100
(OtherWorker) Progress: 72/100
(OtherWorker) Progress: 73/100
(OtherWorker) Progress: 74/100
(OtherWorker) Progress: 75/100
(OtherWorker) Progress: 76/100
(OtherWorker) Progress: 77/100
(OtherWorker) Progress: 78/100
(OtherWorker) Progress: 79/100
(OtherWorker) Progress: 80/100
(OtherWorker) Progress: 81/100
(OtherWorker) Progress: 82/100
(OtherWorker) Progress: 83/100
(OtherWorker) Progress: 84/100
(OtherWorker) Progress: 85/100
(OtherWorker) Progress: 86/100
(OtherWorker) Progress: 87/100
(OtherWorker) Progress: 88/100
(OtherWorker) Progress: 89/100
(OtherWorker) Progress: 90/100
(OtherWorker) Progress: 91/100
(OtherWorker) Progress: 92/100
(OtherWorker) Progress: 93/100
(OtherWorker) Progress: 94/100
(OtherWorker) Progress: 95/100
(OtherWorker) Progress: 96/100
(OtherWorker) Progress: 97/100
(OtherWorker) Progress: 98/100
(OtherWorker) Progress: 99/100
(OtherWorker) Progress: 100/100
(OtherWorker) Finished at 2024/06/17 10:11:41
(AnotherWorker) Started at 2024/06/17 10:11:41
(AnotherWorker) Progress: 0/100
(AnotherWorker) Progress: 1/100
(AnotherWorker) Progress: 2/100
(AnotherWorker) Progress: 3/100
(AnotherWorker) Progress: 4/100
(AnotherWorker) Progress: 5/100
(AnotherWorker) Progress: 6/100
(AnotherWorker) Progress: 7/100
(AnotherWorker) Progress: 8/100
(AnotherWorker) Progress: 9/100
(AnotherWorker) Progress: 10/100
(AnotherWorker) Progress: 11/100
(AnotherWorker) Progress: 12/100
(AnotherWorker) Progress: 13/100
(AnotherWorker) Progress: 14/100
(AnotherWorker) Progress: 15/100
(AnotherWorker) Progress: 16/100
(AnotherWorker) Progress: 17/100
(AnotherWorker) Progress: 18/100
(AnotherWorker) Progress: 19/100
(AnotherWorker) Progress: 20/100
(AnotherWorker) Progress: 21/100
(AnotherWorker) Progress: 22/100
(AnotherWorker) Progress: 23/100
(AnotherWorker) Progress: 24/100
(AnotherWorker) Progress: 25/100
(AnotherWorker) Progress: 26/100
(AnotherWorker) Progress: 27/100
(AnotherWorker) Progress: 28/100
(AnotherWorker) Progress: 29/100
(AnotherWorker) Progress: 30/100
(AnotherWorker) Progress: 31/100
(AnotherWorker) Progress: 32/100
(AnotherWorker) Progress: 33/100
(AnotherWorker) Progress: 34/100
(AnotherWorker) Progress: 35/100
(AnotherWorker) Progress: 36/100
(AnotherWorker) Progress: 37/100
(AnotherWorker) Progress: 38/100
(AnotherWorker) Progress: 39/100
(AnotherWorker) Progress: 40/100
(AnotherWorker) Progress: 41/100
(AnotherWorker) Progress: 42/100
(AnotherWorker) Progress: 43/100
(AnotherWorker) Progress: 44/100
(AnotherWorker) Progress: 45/100
(AnotherWorker) Progress: 46/100
(AnotherWorker) Progress: 47/100
(AnotherWorker) Progress: 48/100
(AnotherWorker) Progress: 49/100
(AnotherWorker) Progress: 50/100
(AnotherWorker) Progress: 51/100
(AnotherWorker) Progress: 52/100
(AnotherWorker) Progress: 53/100
(AnotherWorker) Progress: 54/100
(AnotherWorker) Progress: 55/100
(AnotherWorker) Progress: 56/100
(AnotherWorker) Progress: 57/100
(AnotherWorker) Progress: 58/100
(AnotherWorker) Progress: 59/100
(AnotherWorker) Progress: 60/100
(AnotherWorker) Progress: 61/100
(AnotherWorker) Progress: 62/100
(AnotherWorker) Progress: 63/100
(AnotherWorker) Progress: 64/100
(AnotherWorker) Progress: 65/100
(AnotherWorker) Progress: 66/100
(AnotherWorker) Progress: 67/100
(AnotherWorker) Progress: 68/100
(AnotherWorker) Progress: 69/100
(AnotherWorker) Progress: 70/100
(AnotherWorker) Progress: 71/100
(AnotherWorker) Progress: 72/100
(AnotherWorker) Progress: 73/100
(AnotherWorker) Progress: 74/100
(AnotherWorker) Progress: 75/100
(AnotherWorker) Progress: 76/100
(AnotherWorker) Progress: 77/100
(AnotherWorker) Progress: 78/100
(AnotherWorker) Progress: 79/100
(AnotherWorker) Progress: 80/100
(AnotherWorker) Progress: 81/100
(AnotherWorker) Progress: 82/100
(AnotherWorker) Progress: 83/100
(AnotherWorker) Progress: 84/100
(AnotherWorker) Progress: 85/100
(AnotherWorker) Progress: 86/100
(AnotherWorker) Progress: 87/100
(AnotherWorker) Progress: 88/100
(AnotherWorker) Progress: 89/100
(AnotherWorker) Progress: 90/100
(AnotherWorker) Progress: 91/100
(AnotherWorker) Progress: 92/100
(AnotherWorker) Progress: 93/100
(AnotherWorker) Progress: 94/100
(AnotherWorker) Progress: 95/100
(AnotherWorker) Progress: 96/100
(AnotherWorker) Progress: 97/100
(AnotherWorker) Progress: 98/100
(AnotherWorker) Progress: 99/100
(AnotherWorker) Progress: 100/100
(AnotherWorker) Finished at 2024/06/17 10:11:41
(DownloadWorker) Started at 2024/06/17 10:11:41
(DownloadWorker) Progress: 0/100
(DownloadWorker) Progress: 1/100
(DownloadWorker) Progress: 2/100
(DownloadWorker) Progress: 3/100
(DownloadWorker) Progress: 4/100
(DownloadWorker) Progress: 5/100
(DownloadWorker) Progress: 6/100
(DownloadWorker) Progress: 7/100
(DownloadWorker) Progress: 8/100
(DownloadWorker) Progress: 9/100
(DownloadWorker) Progress: 10/100
(DownloadWorker) Progress: 11/100
(DownloadWorker) Progress: 12/100
(DownloadWorker) Progress: 13/100
(DownloadWorker) Progress: 14/100
(DownloadWorker) Progress: 15/100
(DownloadWorker) Progress: 16/100
(DownloadWorker) Progress: 17/100
(DownloadWorker) Progress: 18/100
(DownloadWorker) Progress: 19/100
(DownloadWorker) Progress: 20/100
(DownloadWorker) Progress: 21/100
(DownloadWorker) Progress: 22/100
(DownloadWorker) Progress: 23/100
(DownloadWorker) Progress: 24/100
(DownloadWorker) Progress: 25/100
(DownloadWorker) Progress: 26/100
(DownloadWorker) Progress: 27/100
(DownloadWorker) Progress: 28/100
(DownloadWorker) Progress: 29/100
(DownloadWorker) Progress: 30/100
(DownloadWorker) Progress: 31/100
(DownloadWorker) Progress: 32/100
(DownloadWorker) Progress: 33/100
(DownloadWorker) Progress: 34/100
(DownloadWorker) Progress: 35/100
(DownloadWorker) Progress: 36/100
(DownloadWorker) Progress: 37/100
(DownloadWorker) Progress: 38/100
(DownloadWorker) Progress: 39/100
(DownloadWorker) Progress: 40/100
(DownloadWorker) Progress: 41/100
(DownloadWorker) Progress: 42/100
(DownloadWorker) Progress: 43/100
(DownloadWorker) Progress: 44/100
(DownloadWorker) Progress: 45/100
(DownloadWorker) Progress: 46/100
(DownloadWorker) Progress: 47/100
(DownloadWorker) Progress: 48/100
(DownloadWorker) Progress: 49/100
(DownloadWorker) Progress: 50/100
(DownloadWorker) Progress: 51/100
(DownloadWorker) Progress: 52/100
(DownloadWorker) Progress: 53/100
(DownloadWorker) Progress: 54/100
(DownloadWorker) Progress: 55/100
(DownloadWorker) Progress: 56/100
(DownloadWorker) Progress: 57/100
(DownloadWorker) Progress: 58/100
(DownloadWorker) Progress: 59/100
(DownloadWorker) Progress: 60/100
(DownloadWorker) Progress: 61/100
(DownloadWorker) Progress: 62/100
(DownloadWorker) Progress: 63/100
(DownloadWorker) Progress: 64/100
(DownloadWorker) Progress: 65/100
(DownloadWorker) Progress: 66/100
(DownloadWorker) Progress: 67/100
(DownloadWorker) Progress: 68/100
(DownloadWorker) Progress: 69/100
(DownloadWorker) Progress: 70/100
(DownloadWorker) Progress: 71/100
(DownloadWorker) Progress: 72/100
(DownloadWorker) Progress: 73/100
(DownloadWorker) Progress: 74/100
(DownloadWorker) Progress: 75/100
(DownloadWorker) Progress: 76/100
(DownloadWorker) Progress: 77/100
(DownloadWorker) Progress: 78/100
(DownloadWorker) Progress: 79/100
(DownloadWorker) Progress: 80/100
(DownloadWorker) Progress: 81/100
(DownloadWorker) Progress: 82/100
(DownloadWorker) Progress: 83/100
(DownloadWorker) Progress: 84/100
(DownloadWorker) Progress: 85/100
(DownloadWorker) Progress: 86/100
(DownloadWorker) Progress: 87/100
(DownloadWorker) Progress: 88/100
(DownloadWorker) Progress: 89/100
(DownloadWorker) Progress: 90/100
(DownloadWorker) Progress: 91/100
(DownloadWorker) Progress: 92/100
(DownloadWorker) Progress: 93/100
(DownloadWorker) Progress: 94/100
(DownloadWorker) Progress: 95/100
(DownloadWorker) Progress: 96/100
(DownloadWorker) Progress: 97/100
(DownloadWorker) Progress: 98/100
(DownloadWorker) Progress: 99/100
(DownloadWorker) Progress: 100/100
(DownloadWorker) Finished at 2024/06/17 10:11:42
이하 생략
ChainInitiationWorker가 RUNNING 상태 후 굉장히 빨리 ENQUEUED로 전환되었는데, 이는 ChainInitiationWorker의 스레드와 다른 별도의 스레드에서 ChainInitiationWorker 내부의 WorkRequest가 진행되었기 때문으로 보인다.
#5 요약
Worker를 Chain화함으로써, 더 가독성 좋고 유연한 프로젝트 구조를 달성할 수 있다.
#6 완성된 앱
#7 이어지는 글
본 게시글이 Worker를 '직렬'로 연결한 것이라면, 이어지는 글에서는 Worker를 '병렬'로도 연결해본다.
'깨알 개념 > Android' 카테고리의 다른 글
[Android] Dagger2 - 기초 (0) | 2024.06.24 |
---|---|
[Android] WorkManager - 병렬 Chaining (0) | 2024.06.17 |
[Android] WorkManager - 제약 조건 (Constraints) (0) | 2024.06.17 |
[Android] WorkManager - 인자 전달 및 데이터 반환 (0) | 2024.06.17 |
[Android] WorkManager - enqueueUniqueWork() (0) | 2024.06.17 |