-
Notifications
You must be signed in to change notification settings - Fork 638
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Paolo Di Tommaso <[email protected]>
- Loading branch information
1 parent
1d32e2c
commit d7e38e9
Showing
2 changed files
with
30 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() { | ||
|
@@ -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() ] | ||
} | ||
|
@@ -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 | ||
} | ||
} | ||
} |