Skip to content

Commit 4c8bc52

Browse files
authored
Merge pull request #43 from VEuPathDB/issue-42
Add method for retrieving a single file.
2 parents ea103fb + ec07eae commit 4c8bc52

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

lib/src/main/kotlin/org/veupathdb/lib/compute/platform/AsyncPlatform.kt

+18
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,24 @@ object AsyncPlatform {
203203
return S3.getNonReservedFiles(jobID)
204204
}
205205

206+
/**
207+
* Fetches the target file for the target job.
208+
*
209+
* If the target file does not exist, this method returns `null`.
210+
*
211+
* @param jobID Hash ID of the job whose file should be retrieved.
212+
*
213+
* @param fileName Name of the file to retrieve.
214+
*
215+
* @return A reference to the target file, if it exists, otherwise `null`.
216+
*
217+
* @since 1.5.0
218+
*/
219+
fun getJobFile(jobID: HashID, fileName: String): JobFileReference? {
220+
Log.debug("fetching target file \"{}\" for job {}", jobID, fileName)
221+
return S3.getJobFile(jobID, fileName)
222+
}
223+
206224
/**
207225
* Deletes the target job only if it exists, is owned by the current service
208226
* or process, and is in a completed status.

lib/src/main/kotlin/org/veupathdb/lib/compute/platform/intern/s3/S3.kt

+29
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,35 @@ internal object S3 {
186186
return out
187187
}
188188

189+
/**
190+
* Attempts to fetch the target file from the target workspace.
191+
*
192+
* If the target workspace is not found, an [IllegalStateException] will be
193+
* thrown.
194+
*
195+
* If the target file is not found, `null` will be returned.
196+
*
197+
* @param jobID ID of the workspace from which the target job should be
198+
* fetched.
199+
*
200+
* @return A handle on the target file, if it exists, or `null`.
201+
*
202+
* @since 1.5.0
203+
*/
204+
@JvmStatic
205+
fun getJobFile(jobID: HashID, fileName: String): JobFileReference? {
206+
Log.debug("fetching target file \"{}\" for job {} in S3", fileName, jobID)
207+
208+
// Load the workspace
209+
val ws = wsf[jobID] ?: throw IllegalStateException("attempted to fetch target file from nonexistent workspace $jobID")
210+
211+
// Sift through the files for one matching the target file name and return
212+
// it (or null if none were found).
213+
return ws.files()
214+
.firstOrNull { it.name == fileName }
215+
?.let(::JobFileReferenceImpl)
216+
}
217+
189218
/**
190219
* Clears out the target workspace and marks it as `expired`.
191220
*

0 commit comments

Comments
 (0)