Skip to content

Commit

Permalink
Fix Google Batch logging exception
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso committed Mar 19, 2023
1 parent 1d32e2c commit d7e38e9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class GoogleBatchExecutor extends Executor implements ExtensionPoint {
@Override
void shutdown() {
client.shutdown()
logging.close()
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ import nextflow.cloud.google.batch.client.BatchConfig
* @author Paolo Di Tommaso <[email protected]>
*/
@Slf4j
class BatchLogging {
class BatchLogging implements Closeable {
private LoggingOptions opts
private String projectId
private volatile Logging logging0

/** only for testing - do not use */
protected BatchLogging() {
Expand Down Expand Up @@ -68,17 +69,15 @@ class BatchLogging {
@PackageScope List<String> fetchLogs(String uid) {
final stdout = new StringBuilder()
final stderr = new StringBuilder()
try(Logging logging = opts.getService()) {
// use logging here
final filter = "resource.type=generic_task AND logName=\"projects/${projectId}/logs/batch_task_logs\" AND labels.job_uid=$uid"
final entries = logging.listLogEntries(
Logging.EntryListOption.filter(filter),
Logging.EntryListOption.pageSize(1000) )
// use logging here
final filter = "resource.type=generic_task AND logName=\"projects/${projectId}/logs/batch_task_logs\" AND labels.job_uid=$uid"
final entries = loggingService().listLogEntries(
Logging.EntryListOption.filter(filter),
Logging.EntryListOption.pageSize(1000) )

final page = entries.getValues()
for (LogEntry logEntry : page.iterator()) {
parseOutput(logEntry, stdout, stderr)
}
final page = entries.getValues()
for (LogEntry logEntry : page.iterator()) {
parseOutput(logEntry, stdout, stderr)
}
return [ stdout.toString(), stderr.toString() ]
}
Expand All @@ -91,4 +90,23 @@ class BatchLogging {
stdout.append(output)
}
}

synchronized protected loggingService() {
if( logging0==null ) {
logging0 = opts.getService()
}
return logging0
}

@Override
void close() throws IOException {
if( logging0==null )
return
try {
logging0.close()
}
catch (Exception e) {
log.debug "Unexpected error closing Google Logging service", e
}
}
}

0 comments on commit d7e38e9

Please sign in to comment.