-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtil.gs
50 lines (46 loc) · 763 Bytes
/
Util.gs
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
function log(msg)
{
if (logging)
{
Logger.log(msg);
}
}
function debug(msg)
{
if (debuging)
{
Logger.log(msg);
}
}
function warn(msg)
{
if (warning)
{
Logger.log(msg);
}
}
function retry(max, func) {
for (var n=0; n<=max; n++) {
try {
return func();
} catch(e) {
Utilities.sleep((Math.pow(2,n)*2000) + (Math.round(Math.random() * 2000)));
}
}
}
function lock(timeout, func) {
try {
var lock = LockService.getScriptLock();
if (lock.tryLock(timeout*1000)) {
try {
func();
} finally {
lock.releaseLock();
}
} else {
warn('Could not obtain lock after ' + timeout + ' seconds.');
}
} catch (e) {
warn('Could not obtain lock service.');
}
}