-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjobScheduler.js
More file actions
54 lines (48 loc) · 1.62 KB
/
Copy pathjobScheduler.js
File metadata and controls
54 lines (48 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"use strict";
import { NativeModules, AppRegistry } from "react-native";
const AppState = NativeModules.AppState;
const tag = "AsyncJob:";
const jobModule = NativeModules.AsyncJob;
import AbstractAsyncTask from './abstractAsyncTask'
import TaskRegistry from './taskRegistry'
const JobScheduler = {
NETWORK_TYPE_UNMETERED: jobModule.UNMETERED,
NETWORK_TYPE_NONE: jobModule.NONE,
NETWORK_TYPE_ANY: jobModule.ANY,
scheduleJob: function(taskObj) {
if(taskObj instanceof AbstractAsyncTask) {
console.log(taskObj);
if(TaskRegistry.isRegisteredTask(taskObj.getTaskName())) {
if(taskObj.getTaskId()) {
AppState.getCurrentAppState(
({ app_state }) => {
const appActive = app_state == "active";
jobModule.scheduleAsyncJob(
taskObj.getTaskId(),
taskObj.getTaskName(),
taskObj.getTimeout(),
taskObj.getPeriod(),
taskObj.isPersistedTask(),
appActive,
taskObj.allowInForeground(),
taskObj.getNetworkPrefrence(),
taskObj.isChargingNeeded(),
taskObj.isDeviceIdleNeeded(),
taskObj.isOneTimeJob(),
taskObj.getTaskPayload(),
taskObj.postSchedule
);
},
() => console.err(`${tag} Can't get Current App State`)
);
}
console.log("Done scheduling")
}else {
console.error("Task is not registred ", taskObj);
}
}else {
console.error("Not a valid Task Object")
}
},
};
module.exports = JobScheduler;