Skip to content

Commit

Permalink
fix : defined global interval & changing from test to ready
Browse files Browse the repository at this point in the history
  • Loading branch information
kalisio-nicolas committed Feb 7, 2024
1 parent d787673 commit e532f28
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/entrypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const TTS = env.TTS || console.error("TTS not defined, process will run indefini
const TIMEZONE = env.TIMEZONE || "Europe/Paris"
const jobs = env.JOBS || 1

var interval = null


console.log("Starting process with args:")
console.log("ROLE:", ROLE)
Expand Down Expand Up @@ -61,7 +63,7 @@ process.on('SIGTERM', stop);

if (env.TTS){
setTimeout(stop, get_time_to_stop(TTS, TIMEZONE)*1000)
const interval=setInterval(() => {
interval=setInterval(() => {
console.log("Process will stop in", get_time_to_stop(TTS, TIMEZONE)/60, "minutes")
}, 1000*60*5)

Expand Down
12 changes: 11 additions & 1 deletion src/master_updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const DEP_TO_EXCLUDE = env.DEP_TO_EXCLUDE || ''
fs.mkdirSync(opts.tmpDir, { recursive: true })


// Step 1: We if the workers have finished their tasks (if their volume is empty)
// Step 1: We if the workers have finished their tasks (if their volume is empty or their "todo" dir is empty or their "workdir" dir is empty)
const workers = fs.readdirSync(opts.volumes)
workers.forEach(worker =>{
if (fs.readdirSync(path.join(opts.volumes, worker)).length > 0){
Expand Down Expand Up @@ -52,6 +52,16 @@ update_links.forEach(link =>{
})


// step 5: We remove the todo dir of the workers that have no tasks to remove confusion for the next run
workers.forEach(worker =>{
if (nb_tasks_per_worker[worker] == 0){
exec('rm', ['-rf', path.join(opts.volumes, worker, 'todo')])
}
})




console.log('All tasks were dispatched to workers')
// Remove the "tmp" dir
exec('rm', ['-rf', opts.tmpDir])
Expand Down
10 changes: 5 additions & 5 deletions src/worker_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ process.on('SIGTERM', () => {
console.log("Failed links:", get_num_failed())
console.log("Done links:", get_num_done())
console.log("Current link:", current_link)
slack_log(`*TEST_BDORTHO*: interrupting work on *${hostname}*, *[${get_num_total()}/${current_link ? 1 : 0}/${get_num_done()}/${get_num_failed()}]* (total/pending/success/failed).`, '#d15c21', slack_url)
slack_log(`*BDORTHO*: interrupting work on *${hostname}*, *[${get_num_total()}/${current_link ? 1 : 0}/${get_num_done()}/${get_num_failed()}]* (total/pending/success/failed).`, '#d15c21', slack_url)

// We kill the worker process
exec('pkill', ['-f', 'worker_process.js'])
Expand Down Expand Up @@ -142,7 +142,7 @@ async function main(){
current_link=get_new_link()
if (current_link){
console.log("Starting worker process...")
slack_log(`*TEST_BDORTHO*: resuming work on *${hostname}*, *[${get_num_total()}/${current_link ? 1 : 0}/${get_num_done()}/${get_num_failed()}]* (total/pending/success/failed).`, '#d15c21', slack_url)
slack_log(`*BDORTHO*: resuming work on *${hostname}*, *[${get_num_total()}/${current_link ? 1 : 0}/${get_num_done()}/${get_num_failed()}]* (total/pending/success/failed).`, '#d15c21', slack_url)
}

while(current_link!=null){
Expand All @@ -157,18 +157,18 @@ async function main(){
if (code == 0) {
console.log("Process for link", path.basename(current_link)," exited successfully")
add_to_done(current_link)
slack_log(`*TEST_BDORTHO*: *${path.basename(current_link)}* done on *${hostname}* [${get_num_done()}/${get_num_total()}] (success/total).`, '#2eb886', slack_url)
slack_log(`*BDORTHO*: *${path.basename(current_link)}* done on *${hostname}* [${get_num_done()}/${get_num_total()}] (success/total).`, '#2eb886', slack_url)
}
else{
console.log("Process for link", path.basename(current_link)," exited with error: ", ERR_CODES[code] || code )
add_to_failed(current_link)
slack_log(`*TEST_BDORTHO*: *${path.basename(current_link)}* failed on *${hostname}* with error: ${ERR_CODES[code] || code}, *[${get_num_total()}/${get_num_done()}/${get_num_failed()}]* (total/success/failed).`, '#d50200', slack_url)
slack_log(`*BDORTHO*: *${path.basename(current_link)}* failed on *${hostname}* with error: ${ERR_CODES[code] || code}, *[${get_num_total()}/${get_num_done()}/${get_num_failed()}]* (total/success/failed).`, '#d50200', slack_url)
}
}
catch (e) {
console.log("Process exited with an unknown error", e)
add_to_failed(current_link)
slack_log(`*TEST_BDORTHO*: *${path.basename(current_link)}* failed on *${hostname}* *[${get_num_total()}/${get_num_done()}/${get_num_failed()}]* (total/success/failed).`, '#d50200', slack_url)
slack_log(`*BDORTHO*: *${path.basename(current_link)}* failed on *${hostname}* *[${get_num_total()}/${get_num_done()}/${get_num_failed()}]* (total/success/failed).`, '#d50200', slack_url)
}
current_link=get_new_link()
}
Expand Down

0 comments on commit e532f28

Please sign in to comment.