-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
executable file
·102 lines (90 loc) · 2.44 KB
/
init.lua
File metadata and controls
executable file
·102 lines (90 loc) · 2.44 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
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
require 'sys'
batcher = {}
require 'batcher.helpers'
do
if batcher.type ~= nil then
print "Only call require 'batcher' or require 'batcher.batch' not both"
error()
end
batcher.type = 'init'
local timelimit = function() return 900 end
local i = 0
local done = false
local tokenWait = 10
local waitLimit = 7200
local backupDuringRun = false
local waitForLimit = false -- Wait for limit before trying to grab the token
local cmd = function(arguments) return 'th ' .. arguments end
local checkpointFile = 'batcher-checkpoint.t7'
local tokenFile = 'batcher-token.t7'
local batcherExtra = ''
batcher.set_token(tokenFile)
if tokenWait <= 0 then
print("Token wait time should be positive")
error()
end
function batcher.cmd(batch_cmd)
if type(batch_cmd) ~= "function" then
cmd = function(arguments) return batch_cmd .. ' ' .. arguments end
else
cmd = batch_cmd
end
end
function batcher.backupDuringRun(value)
backupDuringRun = value
end
function batcher.timelimit(limit)
if type(limit) ~= "function" then
timelimit = function() return limit end
else
timelimit = limit
end
end
function batcher.checkpointFile(file)
checkpointFile = file
end
function batcher.tokenFile(file)
tokenFile = file
batcher.set_token(file)
end
function batcher.stop()
done = true
end
function batcher.batcherExtra(extra)
batcherExtra = extra -- e.g. to set -batcherBackupDuringRun
end
function batcher.arguments(limit)
return string.format("-batcher ".. batcherExtra .." -batcherTimelimit %f -batcherCheckpoint %s -batcherToken %s", limit, checkpointFile, tokenFile)
end
function batcher.launch()
if not batcher.grab_token() then
print("Cannot start: token not free")
error()
end
if done then
print("Previous process results still stored in location")
error()
end
while not done do
local start = sys.clock()
local limit = timelimit()
local command = cmd(batcher.arguments(limit))
print(string.format("Run batch %i", i))
print(command)
res = sys.execute(command)
print(res) -- Print result
while waitForLimit and limit > sys.clock()-start do
sys.sleep(limit-(sys.clock()-start))
end
start = sys.clock()
while not batcher.grab_token() do
if (waitForLimit and waitLimit < sys.clock()-start) or limit+waitLimit < sys.clock()-start then
print("Waiting too long")
error() -- End if we're waiting for too long
end
sys.sleep(tokenWait)
end
i = i + 1
end
end
end