transistorsoft / capacitor-background-fetch

Periodic callbacks in the background for both IOS and Android
78 stars 9 forks source link

after five minutes get data from ionic storage does not work #7

Closed nic86 closed 2 years ago

nic86 commented 2 years ago

Your Environment

Expected Behavior

get data from storage is executed correctly

Actual Behavior

after five minutes the storage does not work and the timeout function is performed

Context

I put the application in the background. I run the script every minute.

adb shell cmd jobscheduler run -f 999

it only works for the first 5 minutes, after which it stops working.

christocracy commented 2 years ago

What does adb logcat show?

nic86 commented 2 years ago

with chrome:inspect i discovered that the problem is not at the http request. Error occurs when in the same function get stored data.

the execution stop here:

async get(key:string):Promise <any> {
    try {
        const val = await this._storage.get(key);    //the execution stop here
        return val;
    } catch(err) {
        return Promise.reject(err);
    }
}

the storage configuration in app.module.ts is

IonicStorageModule.forRoot({
    name: '__dbname',
    driverOrder: [CordovaSQLiteDriver._driver, Drivers.IndexedDB, Drivers.LocalStorage]
}),

adb logcat shows no error.

nic86 commented 2 years ago

adb logcat (first 5 minutes) when the function is running correctly:

08-26 15:57:17.771 17331 17331 D TSBackgroundFetch: - Background Fetch event received: capacitor-background-fetch
08-26 15:57:17.806 17331 17331 I Capacitor/Console: File: http://192.168.0.114:8100/main.js - Line 5266 - Msg: Thu, 26 Aug 2021 13:57:17 GMT :  [BackgroundFetch] EVENT: capacitor-background-fetch
08-26 15:57:17.806 17331 17331 I Capacitor/Console: File: http://192.168.0.114:8100/main.js - Line 5266 - Msg: Thu, 26 Aug 2021 13:57:17 GMT :  start cron process
08-26 15:57:20.207 17331 17489 V Capacitor/Plugin: To native (Capacitor plugin): callbackId: 114360722, pluginId: Http, methodName: get
08-26 15:57:20.294 17331 17489 V Capacitor/Plugin: To native (Capacitor plugin): callbackId: 114360723, pluginId: Http, methodName: get
08-26 15:57:20.298 17331 17489 V Capacitor/Plugin: To native (Capacitor plugin): callbackId: 114360724, pluginId: Http, methodName: get
08-26 15:57:20.401 17331 17489 V Capacitor/Plugin: To native (Capacitor plugin): callbackId: 114360725, pluginId: Http, methodName: get
08-26 15:57:20.405 17331 17489 V Capacitor/Plugin: To native (Capacitor plugin): callbackId: 114360726, pluginId: Http, methodName: get
08-26 15:57:20.484 17331 17489 V Capacitor/Plugin: To native (Capacitor plugin): callbackId: 114360727, pluginId: Http, methodName: get
08-26 15:57:20.496 17331 17489 V Capacitor/Plugin: To native (Capacitor plugin): callbackId: 114360728, pluginId: Http, methodName: get
08-26 15:57:25.898 17331 17331 I Capacitor/Console: File: http://192.168.0.114:8100/main.js - Line 5266 - Msg: Thu, 26 Aug 2021 13:57:25 GMT :  end cron: empty queue
08-26 15:57:25.938 17331 17489 V Capacitor/Plugin: To native (Capacitor plugin): callbackId: 114360729, pluginId: BackgroundFetch, methodName: finish
08-26 15:57:25.942 17331 17453 D TSBackgroundFetch: - finish: capacitor-background-fetch
08-26 15:57:25.942 17331 17453 D TSBackgroundFetch: - jobFinished

adb logcat (after 5 minutes) when the function is not running correctly:

08-26 16:01:01.763 17331 17331 D TSBackgroundFetch: - Background Fetch event received: capacitor-background-fetch
08-26 16:01:01.861 17331 17331 I Capacitor/Console: File: http://192.168.0.114:8100/main.js - Line 5266 - Msg: Thu, 26 Aug 2021 14:01:01 GMT :  [BackgroundFetch] EVENT: capacitor-background-fetch
08-26 16:01:01.863 17331 17331 I Capacitor/Console: File: http://192.168.0.114:8100/main.js - Line 5266 - Msg: Thu, 26 Aug 2021 14:01:01 GMT :  start cron process
08-26 16:02:01.795 17331 17331 D TSBackgroundFetch: [BGTask] timeout: capacitor-background-fetch
08-26 16:02:01.847 17331 17331 I Capacitor/Console: File: http://192.168.0.114:8100/main.js - Line 5266 - Msg: Thu, 26 Aug 2021 14:02:01 GMT :  [BackgroundFetch] TIMEOUT: capacitor-background-fetch
08-26 16:02:01.853 17331 17489 V Capacitor/Plugin: To native (Capacitor plugin): callbackId: 114360730, pluginId: BackgroundFetch, methodName: finish
08-26 16:02:01.853 17331 17453 D TSBackgroundFetch: - finish: capacitor-background-fetch
08-26 16:02:01.853 17331 17453 D TSBackgroundFetch: - jobFinished

i have tested ionic storage driver CordovaSQLiteDriver._driver and Drivers.IndexedDB but neither works

IonicStorageModule.forRoot({
    name: '__dbname',
    driverOrder: [CordovaSQLiteDriver._driver, Drivers.IndexedDB, Drivers.LocalStorage]
}),
IonicStorageModule.forRoot({
    name: '__dbname',
    driverOrder: [Drivers.IndexedDB, Drivers.LocalStorage]
}),
nic86 commented 2 years ago

I tested the ionic driver Drivers.LocalStorage and now it seems to work even after 5 minutes.

IonicStorageModule.forRoot({
    name: '__dbname',
    driverOrder: [Drivers.LocalStorage, Drivers.IndexedDB]
}),
christocracy commented 2 years ago

You seem to be having problems with a 3rd party plugin you're using within your fetch callback.

I see the fetch events operating correctly.

14:01:01 GMT : [BackgroundFetch] EVENT: capacitor-background-fetch

08-26 16:02:01.795 17331 17331 D TSBackgroundFetch: [BGTask] timeout: capacitor-background-fetch