@@ -92,7 +92,7 @@ tmux_spawn_workers_from_df <- function(df,
9292 delay_after_layout = 0.4 ,
9393 delay_between_R_start = 0.0 ,
9494 delay_before_source = 60 ,
95- stagger_by = 60 ,
95+ stagger_by = delay_before_source ,
9696 set_mouse = TRUE ,
9797 # --- new arguments ---
9898 continue = TRUE ,
@@ -132,6 +132,8 @@ tmux_spawn_workers_from_df <- function(df,
132132
133133 # 1. Create a new pane for the sync process
134134 if (! is.null(queue_path )) {
135+ tmux_refresh_queue_status(queue_path )
136+
135137 if (! is.null(ss_id )) {
136138 isDir <- reproducible ::: isGoogleDriveDirectory(ss_id )
137139 if (isTRUE(isDir )) {
@@ -179,7 +181,7 @@ tmux_spawn_workers_from_df <- function(df,
179181 .tmux_run(" select-layout" , " -t" , target_win , " tiled" )
180182 .tmux_run(" select-pane" , " -t" , mon_id , " -T" , " Cluster_Monitor" )
181183
182- full_bash_mon_cmd <- sprintf(" Rscript -e %s" , shQuote(mon_cmd ))
184+ full_bash_mon_cmd <- sprintf(" Rscript -e %s" , shQuote(mon_cmd ))
183185 .tmux_run(" send-keys" , " -t" , mon_id , full_bash_mon_cmd , " C-m" )
184186
185187
@@ -200,8 +202,9 @@ tmux_spawn_workers_from_df <- function(df,
200202 )
201203
202204 # 3. Send keys to the specific ID
203- # Adding a leading space ' ' prevents the command from being saved in bash history
204- full_bash_cmd <- sprintf(" Rscript -e %s" , shQuote(sync_cmd ))
205+ # Adding a leading space ' ' prevents the command from being saved in bash history;
206+ # I took this away because I wanted access to the command
207+ full_bash_cmd <- sprintf(" Rscript -e %s" , shQuote(sync_cmd ))
205208 .tmux_run(" send-keys" , " -t" , sync_pane_id , full_bash_cmd , " C-m" )
206209
207210 # 4. Label the pane for clarity
@@ -269,16 +272,17 @@ tmux_spawn_workers_from_df <- function(df,
269272 queue_path <- file.path(dirname(normalizePath(global_path )), " tmux_queue.rds" )
270273 }
271274 tmux_prepare_queue_from_df(df , queue_path )
275+ tmux_refresh_queue_status(queue_path )
272276 # Warn if filelock missing (workers will error in panes if not installed)
273277 if (! requireNamespace(" filelock" , quietly = TRUE )) {
274278 warning(" Workers require 'filelock' installed on the host. Install with install.packages('filelock')." )
275279 }
276280 worker_script <- .write_worker_loop(queue_path , global_path ,
277281 on_interrupt = on_interrupt , on_error = on_error )
278-
279282 for (i in seq_along(workers )) {
280283 pre_sleep <- if (i == 1L ) 0 else (delay_before_source + max(0 , i - 2 ) * stagger_by )
281284 code <- sprintf(" Sys.sleep(%s); source(%s)" , pre_sleep , deparse(worker_script ))
285+ # This next line starts the source("global.R")
282286 .tmux_run(" send-keys" , " -t" , workers [i ], code , " C-m" )
283287 }
284288 }
@@ -477,7 +481,8 @@ tmux_prepare_queue_from_df <- function(df, queue_path) {
477481
478482
479483 # 3. Find all PENDING rows
480- pending_idx <- which(q$status == " PENDING " )
484+ # pending_idx <- which(q$status == " PENDING " )
485+ pending_idx <- which(q$status %%in%% c(" INTERRUPTED " , " PENDING " ))[1]
481486
482487 if (length(pending_idx) == 0) {
483488 filelock::unlock(lck)
@@ -594,7 +599,7 @@ tmux_prepare_queue_from_df <- function(df, queue_path) {
594599# ' @param elfind_path Directory containing the figures/hists
595600# ' @param timeout_min Threshold for inactivity (e.g., 20)
596601.assess_sim_visual_status <- function (elfind_path , timeout_min = 20 ) {
597- hdir <- file.path(" outputs" , elfind_path , " figures" , " hists " )
602+ hdir <- file.path(" outputs" , elfind_path , " figures" , " objFun " )
598603 if (! dir.exists(hdir )) return (" PENDING" )
599604
600605 # Find most recent PNG
@@ -622,8 +627,9 @@ tmux_prepare_queue_from_df <- function(df, queue_path) {
622627 has_red <- red_pixels > 0
623628
624629 if (has_red ) {
625- return (" FINISHED " )
630+ return (" DONE " )
626631 } else {
632+ # return("DONE")
627633 return (" INTERRUPTED" )
628634 }
629635}
@@ -653,28 +659,34 @@ tmux_prepare_queue_from_df <- function(df, queue_path) {
653659# ' tmux_refresh_queue_status("experiment_queue.rds", timeout_min = 30)
654660# ' }
655661tmux_refresh_queue_status <- function (queue_path , timeout_min = 20 ) {
656- lck <- filelock :: lock(paste0(queue_path , " .lock" ), timeout = 10000 )
657- if (is.null(lck )) stop(" Could not lock queue for refresh." )
658-
659- q <- readRDS(queue_path )
660-
661- # Only refresh rows that aren't already marked DONE
662- to_check <- which(q $ status != " DONE" )
663-
664- for (i in to_check ) {
665- new_status <- .assess_sim_visual_status(q [[" .ELFind" ]][i ], timeout_min )
662+ if (file.exists(queue_path )) {
663+ lck <- filelock :: lock(paste0(queue_path , " .lock" ), timeout = 10000 )
664+ if (is.null(lck )) stop(" Could not lock queue for refresh." )
665+
666+ q <- try(readRDS(queue_path ))
667+ if (is(q , " try-error" )) {
668+ unlink(queue_path )
669+ return (invisible (NULL ))
670+ }
666671
667- # Update status and timestamps if changed
668- if (q $ status [i ] != new_status ) {
669- q $ status [i ] <- new_status
670- # If newly finished, record current time
671- if (new_status == " FINISHED" ) {
672- q $ finished_at [i ] <- format(Sys.time(), " %Y-%m-%d %H:%M:%S" )
672+ # Only refresh rows that aren't already marked DONE
673+ to_check <- which(q $ status != " DONE" )
674+
675+ for (i in to_check ) {
676+ new_status <- .assess_sim_visual_status(q [[" .ELFind" ]][i ], timeout_min )
677+
678+ # Update status and timestamps if changed
679+ if (q $ status [i ] != new_status ) {
680+ q $ status [i ] <- new_status
681+ # If newly finished, record current time
682+ # if (new_status "FINISHED") {
683+ # q$finished_at[i] <- format(Sys.time(), "%Y-%m-%d %H:%M:%S")
684+ # }
673685 }
674686 }
687+
688+ saveRDS(q , queue_path )
689+ filelock :: unlock(lck )
690+ invisible (q )
675691 }
676-
677- saveRDS(q , queue_path )
678- filelock :: unlock(lck )
679- invisible (q )
680692}
0 commit comments