-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrap.js
130 lines (118 loc) · 3.46 KB
/
wrap.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
const ODP = Object.defineProperty;
async function try_until_succ(tsk,max_times=Infinity) {
let R;
let flag =false;
let c = 0;
try {
R = await tsk.launch();
flag = false;
} catch (err) {
flag = true
}
c = c + 1;
/////////////////////////////////
while(flag && c < max_times && !tsk.is_paused()) {
try {
R = await tsk.recover();
flag = false;
} catch(err) {
flag = true
}
c = c + 1
}
return(R)
}
function _hist_push(history,history_size,settled) {
history.push(settled);
if(history.length>history_size) {
history.shift()
} else {}
}
async function limited_auto_recover_loop(tsk,times=1,history_size=10,history=[],counter={}) {
counter.c =0;
while(true && counter.c <times && !tsk.is_paused()) {
if(flag === false) {
try {
let rslt = await tsk.launch();
_hist_push(history,history_size,rslt);
flag = false;
tsk.soft_reset();
} catch (err) {
_hist_push(history,history_size,err);
flag = true
}
counter.c = counter.c +1
} else {
try {
R = await tsk.recover();
_hist_push(history,history_size,rslt);
flag = false;
tsk.soft_reset();
} catch(err) {
_hist_push(history,history_size,err);
flag = true
}
counter.c = counter.c +1
}
}
return({history,counter})
}
function endless_auto_recover_loop(tsk,history_size=10) {
let history = []
let counter = {}
limited_auto_recover_loop(tsk,Infinity,history_size,history,counter);
return({history,counter})
}
async function repeat_until_fail(tsk,times=1,history_size=10,history=[],counter={}) {
counter.c =0;
while(true && counter.c <times && !tsk.is_paused()) {
try {
let rslt = await tsk.launch();
_hist_push(history,history_size,rslt);
tsk.soft_reset();
} catch(err) {
_hist_push(history,history_size,err)
break;
}
counter.c = counter.c+1
}
return({history,counter})
}
async function repeat_ignore_fail(tsk,times=1,history_size=10,history=[],counter={}) {
counter.c =0;
while(true && counter.c <times && !tsk.is_paused()) {
try {
let rslt = await tsk.launch();
_hist_push(history,history_size,rslt);
tsk.soft_reset();
} catch(err) {
_hist_push(history,history_size,err);
tsk.hard_reset();
}
counter.c = counter.c+1
}
return({history,counter})
}
function endless_repeat_loop_until_fail(tsk,history_size=10) {
let history = []
let counter = {}
repeat_until_fail(tsk,Infinity,history_size,history,counter);
return({history,counter})
}
function endless_repeat_loop_ignore_fail(tsk,history_size=10) {
let history = []
let counter = {}
repeat_ignore_fail(tsk,Infinity,history_size,history,counter);
return({history,counter})
}
module.exports = {
////
try_until_succ,
limited_auto_recover_loop,
endless_auto_recover_loop,
////
repeat_until_fail,
repeat_ignore_fail,
endless_repeat_loop_until_fail,
endless_repeat_loop_ignore_fail,
}