WorkManager को डीबग करना

अगर आपको लगता है कि आपके कर्मचारी अक्सर बहुत ज़्यादा काम करते हैं या बिलकुल भी नहीं काम करते हैं, तो यहां कुछ डीबग करने के चरण, जो आपको यह जानने में मदद कर सकते हैं कि क्या हो रहा है.

प्रवेश करना सक्षम करें

यह पता लगाने के लिए कि आपके कर्मचारी ठीक से क्यों नहीं चल रहे हैं, यह verbose WorkManager लॉग देखें. लॉगिंग सक्षम करने के लिए, custom का उपयोग करें शुरू करना.

सबसे पहले, अपने डिवाइस में डिफ़ॉल्ट WorkManagerInitializer को बंद करें AndroidManifest.xml फ़ाइल को लिंक करने के लिए, मेनिफ़ेस्ट-मर्ज का नियम remove लागू किया गया:

<provider
   
android:name="androidx.work.impl.WorkManagerInitializer"
   
android:authorities="${applicationId}.workmanager-init"
   
tools:node="remove"/>

अब डिफ़ॉल्ट WorkManager शुरू करने की सुविधा बंद हो गई है. इसलिए, अब on-मांग पर शुरू करना. ऐसा करने के लिए, android.app.Application क्लास को एक तरीका लागू करना होगा androidx.work.Configuration.Provider के लिए:

KotlinJava
class MyApplication() : Application(), Configuration.Provider {
   
override fun getWorkManagerConfiguration() =
       
Configuration.Builder()
           
.setMinimumLoggingLevel(android.util.Log.DEBUG)
           
.build()
}
public class MyApplication extends Application implements Configuration.Provider {
   
@NonNull
   
@Override
   
public Configuration getWorkManagerConfiguration() {
       
return new Configuration.Builder()
               
.setMinimumLoggingLevel(android.util.Log.DEBUG)
               
.build();
   
}
}

जब आप कस्टम WorkManager कॉन्फ़िगरेशन तय करते हैं, तो आपका WorkManager आपके कॉल करने पर शुरू हो जाता है WorkManager.getInstance(Context) पर अपने-आप अपडेट हो जाती है. कस्टम वर्क मैनेजर देखें कॉन्फ़िगरेशन और प्रोसेस शुरू करना और ज़्यादा जानकारी के लिए, जिसमें WorkManager के वर्शन से पहले 2.1.0.

DEBUG में लॉग इन करने की सुविधा चालू होने पर, लॉग-टैग प्रीफ़िक्स WM- के साथ बहुत ज़्यादा लॉग देखें.

adb Shell डंपसिस जॉबशेड्यूलर का इस्तेमाल करें

आप Android 6.0 पर काम शेड्यूल करने के बारे में ज़्यादा जानकारी पाने के लिए adb का इस्तेमाल कर सकते हैं (एपीआई लेवल 23) या उसके बाद वाला वर्शन. अगर आपने इससे पहले adb का इस्तेमाल नहीं किया है, तो कमांड-लाइन देखें ज़्यादा जानकारी के लिए, टूल का इस्तेमाल करें.

जब आप adb इंस्टॉल कर लें, तो की सूची देखने के लिए नीचे दिया गया कमांड चलाएं आपके पैकेज से जुड़ी नौकरियों के लिए:

adb shell dumpsys jobscheduler

आउटपुट कुछ ऐसा दिखेगा:

JOB #u0a172/4: 6412553 com.google.android.youtube/androidx.work.impl.background.systemjob.SystemJobService
  u0a172 tag
=*job*/com.google.android.youtube/androidx.work.impl.background.systemjob.SystemJobService
 
Source: uid=u0a172 user=0 pkg=com.google.android.youtube
 
JobInfo:
   
Service: com.google.android.youtube/androidx.work.impl.background.systemjob.SystemJobService
   
Requires: charging=false batteryNotLow=false deviceIdle=false
   
Extras: mParcelledData.dataSize=180
   
Network type: NetworkRequest [ NONE id=0, [ Capabilities: NOT_METERED&INTERNET&NOT_RESTRICTED&TRUSTED&VALIDATED Uid: 10172] ]
   
Minimum latency: +1h29m59s687ms
   
Backoff: policy=1 initial=+30s0ms
   
Has early constraint
 
Required constraints: TIMING_DELAY CONNECTIVITY [0x90000000]
 
Satisfied constraints: DEVICE_NOT_DOZING BACKGROUND_NOT_RESTRICTED WITHIN_QUOTA [0x3400000]
 
Unsatisfied constraints: TIMING_DELAY CONNECTIVITY [0x90000000]
 
Tracking: CONNECTIVITY TIME QUOTA
 
Implicit constraints:
    readyNotDozing
: true
    readyNotRestrictedInBg
: true
 
Standby bucket: RARE
 
Base heartbeat: 0
 
Enqueue time: -51m29s853ms
 
Run time: earliest=+38m29s834ms, latest=none, original latest=none
 
Last run heartbeat: 0
 
Ready: false (job=false user=true !pending=true !active=true !backingup=true comp=true)

WorkManager का इस्तेमाल करते समय, वर्कर के काम करने की प्रोसेस को मैनेज करने वाला कॉम्पोनेंट एपीआई लेवल 23 या उसके बाद के लेवल पर SystemJobService है. जॉब के इंस्टेंस देखें जिनका श्रेय आपके पैकेज के नाम को दिया जाता है और androidx.work.impl.background.systemjob.SystemJobService.

हर काम के लिए, निर्देश में दिए गए आउटपुट में ज़रूरी है, संतुष्ट, और संतुष्ट नहीं हैं. देखें कि आपके कर्मचारी की तय की गई सीमाएं पूरी तरह से संतुष्ट हैं.

आउटपुट में, हाल ही में लागू की गई जॉब का इतिहास भी शामिल होता है, ताकि आप यह जांचता है कि क्या SystemJobService का हाल ही में शुरू हुआ था.

Job history:
     
-1h35m26s440ms   START: #u0a107/9008 com.google.android.youtube/androidx.work.impl.background.systemjob.SystemJobService
     
-1h35m26s362ms  STOP-P: #u0a107/9008 com.google.android.youtube/androidx.work.impl.background.systemjob.SystemJobService app called jobFinished

WorkManager 2.4.0+ से, गड़बड़ी की जानकारी का अनुरोध करना

अपने ऐप्लिकेशन के डीबग बिल्ड पर, गड़बड़ी की जानकारी का अनुरोध यहां किया जा सकता है WorkManager 2.4.0 और इसके बाद के वर्शन में ये निर्देश इस्तेमाल किए जा सकते हैं:

adb shell am broadcast -a "androidx.work.diagnostics.REQUEST_DIAGNOSTICS" -p "<your_app_package_name>"

इससे नीचे दी गई चीज़ों के बारे में जानकारी मिलती है:

  • पिछले 24 घंटों में पूरे किए गए काम के अनुरोध.
  • काम के ऐसे अनुरोध जो अभी चल रहे हैं.
  • शेड्यूल किए गए काम के अनुरोध.

यह कुछ ऐसा दिख सकता है (आउटपुट logcat के ज़रिए दिखता है):

adb shell am broadcast -a "androidx.work.diagnostics.REQUEST_DIAGNOSTICS" -p "androidx.work.integration.testapp"

adb logcat
...
2020-02-13 14:21:37.990 29528-29660/androidx.work.integration.testapp I/WM-DiagnosticsWrkr: Recently completed work:
2020-02-13 14:21:38.083 29528-29660/androidx.work.integration.testapp I/WM-DiagnosticsWrkr: Id  Class Name   State  Unique Name Tags
   
08be261c-2def-4bd6-a716-1e4410968dc4     androidx.work.impl.workers.DiagnosticsWorker    SUCCEEDED  null    androidx.work.impl.workers.DiagnosticsWorker
   
48ce04f1-8df9-450b-96ec-6eceabb9c690     androidx.work.impl.workers.DiagnosticsWorker    SUCCEEDED  null    androidx.work.impl.workers.DiagnosticsWorker
    c46f4699
-c384-440c-a10e-26d56ce02963     androidx.work.impl.workers.DiagnosticsWorker    SUCCEEDED  null    androidx.work.impl.workers.DiagnosticsWorker
    ce125372
-046e-484e-949f-9abb35ce62c3     androidx.work.impl.workers.DiagnosticsWorker    SUCCEEDED  null    androidx.work.impl.workers.DiagnosticsWorker
   
72887ddd-8ed1-4018-b798-fac218e95e16     androidx.work.impl.workers.DiagnosticsWorker    SUCCEEDED  null    androidx.work.impl.workers.DiagnosticsWorker
    dcff3d61
-320d-4996-8644-5d97944bd09c     androidx.work.impl.workers.DiagnosticsWorker    SUCCEEDED  null    androidx.work.impl.workers.DiagnosticsWorker
    acab0bf7
-6087-43ad-bdb5-be0df9195acb     androidx.work.impl.workers.DiagnosticsWorker    SUCCEEDED  null    androidx.work.impl.workers.DiagnosticsWorker
   
23136bcd-01dd-46eb-b910-0fe8a140c2a4     androidx.work.integration.testapp.ToastWorker   SUCCEEDED  null    androidx.work.integration.testapp.ToastWorker
   
245f4879-c6d2-4997-8130-e4e90e1cab4c     androidx.work.integration.testapp.ToastWorker   SUCCEEDED  null    androidx.work.integration.testapp.ToastWorker
   
17d05835-bb61-429a-ad11-fe43fc320a54     androidx.work.integration.testapp.ToastWorker   SUCCEEDED  null    androidx.work.integration.testapp.ToastWorker
    e95f12be
-4b0c-4e64-88da-8ee07a31e42f     androidx.work.integration.testapp.ToastWorker   SUCCEEDED  null    androidx.work.integration.testapp.ToastWorker
   
431c3ec2-4a55-469b-b50b-4072d35f1232     androidx.work.integration.testapp.ToastWorker   SUCCEEDED  null    androidx.work.integration.testapp.ToastWorker
   
883a388f-f911-4098-9143-37bd8fbc098a     androidx.work.integration.testapp.ToastWorker   SUCCEEDED  null    androidx.work.integration.testapp.ToastWorker
    b904163c
-6822-4299-8d5a-78df49b7e53d     androidx.work.integration.testapp.ToastWorker   SUCCEEDED  null    androidx.work.integration.testapp.ToastWorker
   
453fd7b9-2b16-45b9-abc5-3d2ce7b6a4ba     androidx.work.integration.testapp.ToastWorker   SUCCEEDED  null    androidx.work.integration.testapp.ToastWorker
2020-02-13 14:21:38.083 29528-29660/androidx.work.integration.testapp I/WM-DiagnosticsWrkr: Running work:
2020-02-13 14:21:38.089 29528-29660/androidx.work.integration.testapp I/WM-DiagnosticsWrkr: Id  Class Name   State  Unique Name Tags
    b87c8a4f
-4ac6-4e25-ba3e-4cea53ce468a     androidx.work.impl.workers.DiagnosticsWorker    RUNNING    null    androidx.work.impl.workers.DiagnosticsWorker
...