Sync plugin for Telemetry, Course Progress, Assessment

Problem Statement

In the existing app, there are several sync processes running independently, for instance.

  1. All these sync events works on single thread which decreases the current app’s performance.

  2. Telemetry , course progress and course assessment has seperate implementaion in different parts of the app.

Previous Implementaion of telemetry sync flow.

Proposed Solution for the problem

 

Create a custom Cordova plugin which will isolate all sync processes and use a separate DB instance for persistence. This will be natively handled, as a result, the app performance will increase and loosely coupled.

Sync Db with CouchBase Mobile (Prefered)

A full-featured embedded NoSQL database that runs locally on mobile devices which will store the data and sync it to the temporary server, and from temporary server will sync to Platform after that it removes it and so .

Pros:

  • Installation process is easy

  • fast data access

Solution 2: Create a custom Cordova plugin to handle Background task.

WorkManager : Work Manager library does everything for you. It creates the database of your Request and Runs them accordingly.

Architecture:

 there is no need to handle the OS Version checks i-e if OS version is greater then 14 and lower than 21 then use the Job Scheduler Or Service Or Alarm Manager or if OS version is greater than 22 then go for Firebase Job Dispatcher or may you have many other ways like Alarm Manager + Broadcast Receiver to handle your background work but all of them have pros and cons

Some of the other key features of WorkManager include:

  • Persist scheduled work across app updates and device restarts

  • Schedule one-off or periodic tasks

  • Monitor and manage tasks

  • Chain tasks together

Workmanager handles all the conditions of Android OS versions itself and it runs on every device .

  • Uses JobScheduler for API 23+

  • For API 14–22

  • If using Firebase JobDispatcher in the app and the optional Firebase dependency, uses Firebase JobDispatcher

  • Otherwise, uses a custom AlarmManager + BroadcastReceiver implementation

Cons :

  • Consider using Foreground Service. Its also not a great idea to use them for parsing data and contents of view.

 

Plugin Method Defination

 

Plugin method init()

 

init: function(configurations: SyncConfiguration[], success, error) { exec(success, error, PLUGIN_NAME, "init", [configurations]) }

 

export interface SyncConfiguration { type: SyncType; api: { method: "POST" | "PUT" | "PATCH"; host: string; path: string; params: string; }, autoSync: { frequency: number; threshold: number; bandwidth: number; } | undefined, shouldBatch: boolean } export enum SyncType { TELEMETRY = 'TELEMETRY', COURSE_PROGRESS = 'COURSE_PROGRESS', COURSE_ASSESSMENT = 'COURSE_ASSESSMENT' }

sync_config

type

config

 

 

 

 

TELEMETRY

{ "api": { "method": "post", "host": "sample_host", "path": "sample_path", "params": "sample_params" }, "autoSync": { "frequency": 2, "threshold": 200, "bandwidth": 200 }, "shouldBatch": true }

 

 

 

COURSE_PROGRESS

 

 

 

COURSE_ASSESSMENT

 

Course Progress event, Course Assessment event, Telemetry Event will be stored inside a common table

_id

type

key

data

timestamp

priority

_id

type

key

data

timestamp

priority

 

 

 

 

 

 

 

type: sync type(telemetry/progress/assesment)

key: unique identifier

data: event data
timestamp: time when stored

priority: event priority

 

Plugin method save()

It will take type: SyncType and data as a parameter which will store it into the common table with current timestamp and priority

TELEMETRY:

COURSE_PROGRESS:

COURSE_ASSESSMENT:

 

processed_sync_data table

_id

msg_id

type

processed_data

event_count

priority

_id

msg_id

type

processed_data

event_count

priority

 

 

 

 

 

 

 

msg_id: unique msg_id

type: sync type(telemetry/progress/assesment)

processed_data: gzipped data

event count: number of events processed

priority: event priority

 

All the sync processes marked shouldBatch=true will be processed, then gzipped and stored in this table and entries get removed from the table after a successful sync.


Plugin method sync()

Invokes the sync API for the passed ‘type’. In the case of the type defined by autoSync configuration, this is automated within the plugin as defined by the configuration parameters. Additionally invoking sync() method will sync unconditionally regardless of autoSync parameters.