Skip to content
This repository was archived by the owner on Oct 12, 2023. It is now read-only.

Commit a9eec76

Browse files
committed
add setJobAutoDelete function
1 parent 21e529c commit a9eec76

File tree

9 files changed

+62
-33
lines changed

9 files changed

+62
-33
lines changed

CHANGELOG.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
# Change Log
2-
## [0.6.2] 2017-11-17
2+
3+
## [0.6.1] 2017-12-05
34
### Added
5+
- Support for users to use programmatically generated credentials and cluster config
46
- Support for users to delete job and terminate job
57
### Changed
6-
- [BREAKING CHANGE] when wait = TRUE, both job and job results are deleted at the end of the run
8+
- [BREAKING CHANGE] when wait = TRUE, both job and job results are deleted at the end of the run, set jobAutoComplete to FALSE to keep them
79
- Add retry to get job result
810
- Add errorHandling and wait option to job metadata
911
- Save job metadata to job result storage blob
1012

11-
## [0.6.1] 2017-11-13
12-
### Added
13-
- Support for users to use programmatically generated credentials and cluster config
14-
1513
## [0.6.0] 2017-11-03
1614
### Added
1715
- Support for users to run custom versions of R via Docker containers

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export(resizeCluster)
2020
export(setChunkSize)
2121
export(setCredentials)
2222
export(setHttpTraffic)
23+
export(setJobAutoDelete)
2324
export(setReduce)
2425
export(setVerbose)
2526
export(stopCluster)

R/doAzureParallel.R

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ setChunkSize <- function(value = 1) {
7373
assign("chunkSize", value, envir = .doAzureBatchGlobals)
7474
}
7575

76+
#' Specify whether to delete job/jobresult after asychronous job is completed.
77+
#'
78+
#' @param value boolean of TRUE or FALSE
79+
#'
80+
#' @examples
81+
#' setJobAutoDelete(FALSE)
82+
#' @export
83+
setJobAutoDelete <- function(value = TRUE) {
84+
if (!is.logical(value))
85+
stop("setJobAutoDelete requires a boolean argument")
86+
87+
assign("jobAutoDelete", value, envir = .doAzureBatchGlobals)
88+
}
89+
7690
#' Apply reduce function on a group of iterations of the foreach loop together per task.
7791
#'
7892
#' @param fun The number of iterations to group
@@ -232,10 +246,16 @@ setHttpTraffic <- function(value = FALSE) {
232246
wait <- obj$options$azure$wait
233247
}
234248

235-
# by default, delete both job and job result after job is completed (both synchronous and asynchronous)
236-
deleteJob <- TRUE
237-
if (!is.null(obj$options$azure$deleteJob)) {
238-
wait <- obj$options$azure$deleteJob
249+
# by default, delete both job and job result after synchronous job is completed
250+
jobAutoDelete <- TRUE
251+
252+
if (exists("jobAutoDelete", envir = .doAzureBatchGlobals)) {
253+
jobAutoDelete <- get("jobAutoDelete", envir = .doAzureBatchGlobals)
254+
}
255+
256+
if (!is.null(obj$options$azure$jobAutoDelete) &&
257+
is.logical(obj$options$azure$jobAutoDelete)) {
258+
jobAutoDelete <- obj$options$azure$jobAutoDelete
239259
}
240260

241261
inputs <- FALSE
@@ -288,6 +308,10 @@ setHttpTraffic <- function(value = FALSE) {
288308

289309
chunkSize <- 1
290310

311+
if (exists("chunkSize", envir = .doAzureBatchGlobals)) {
312+
chunkSize <- get("chunkSize", envir = .doAzureBatchGlobals)
313+
}
314+
291315
if (!is.null(obj$options$azure$chunkSize)) {
292316
chunkSize <- obj$options$azure$chunkSize
293317
}
@@ -296,10 +320,6 @@ setHttpTraffic <- function(value = FALSE) {
296320
chunkSize <- obj$options$azure$chunksize
297321
}
298322

299-
if (exists("chunkSize", envir = .doAzureBatchGlobals)) {
300-
chunkSize <- get("chunkSize", envir = .doAzureBatchGlobals)
301-
}
302-
303323
chunkSizeKeyValuePair <-
304324
list(name = "chunkSize", value = as.character(chunkSize))
305325

@@ -565,7 +585,7 @@ setHttpTraffic <- function(value = FALSE) {
565585

566586
numberOfFailedTasks <- sum(unlist(failTasks))
567587

568-
if (numberOfFailedTasks > 0 && deleteJob == FALSE) {
588+
if (numberOfFailedTasks > 0 && jobAutoDelete == FALSE) {
569589
.createErrorViewerPane(id, failTasks)
570590
}
571591

@@ -587,7 +607,7 @@ setHttpTraffic <- function(value = FALSE) {
587607
fill = TRUE)
588608

589609
# delete job from batch service and job result from storage blob
590-
if (deleteJob) {
610+
if (jobAutoDelete) {
591611
deleteJob(id)
592612
}
593613

R/jobUtilities.R

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,19 +252,14 @@ getJobResult <- function(jobId) {
252252
#' Delete a job
253253
#'
254254
#' @param jobId A job id
255-
#' @param deleteResult TRUE to delete job result in storage blob
256-
#' container, FALSE to keep the result in storage blob container.
257255
#'
258256
#' @examples
259257
#' \dontrun{
260258
#' deleteJob("job-001")
261-
#' deleteJob("job-001", deleteResult = FALSE)
262259
#' }
263260
#' @export
264-
deleteJob <- function(jobId, deleteResult = TRUE) {
265-
if (deleteResult == TRUE) {
266-
deleteStorageContainer(jobId)
267-
}
261+
deleteJob <- function(jobId) {
262+
deleteStorageContainer(jobId)
268263

269264
response <- rAzureBatch::deleteJob(jobId, content = "response")
270265

docs/31-long-running-job.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ getJob returns job metadata, such as chunk size, whether cloud combine is enable
4343
succeeded: 0
4444
failed: 5
4545
total: 6
46+
47+
job state: completed
4648
```
4749

4850
## Get job list
@@ -81,14 +83,14 @@ Once job is completed successfully, you can call getJobResult to retrieve the jo
8183

8284
### Clean up
8385

84-
Once you get the job result, you can delete the job.
86+
Once you get the job result, you can delete the job and its result.
8587
```R
8688
deleteJob(jobId)
8789
```
8890

89-
Please note deleteJob will delete the job at batch service, by default, it also deletes the storage container holding the job result. If you want to keep the job result around, you can set deleteResult parameter to FALSE
91+
Please note deleteJob will delete the job at batch service and the storage container holding the job result.
9092
```R
91-
deleteJob(jobId, deleteResult = FALSE)
93+
deleteJob(jobId)
9294
```
9395

9496
A [working sample](../samples/long_running_job/long_running_job.R) can be found in the samples directory.

man/deleteJob.Rd

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/setJobAutoDelete.Rd

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/long_running_job/long_running_job.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ jobResult <- getJobResult(jobId)
6565
doAzureParallel::stopCluster(cluster)
6666

6767
# delete the job
68-
rAzureBatch::deleteJob(jobId)
68+
deleteJob(jobId)

tests/testthat/test-long-running-job.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ test_that("Long Running Job Test", {
5252
testthat::expect_equal(jobResult,
5353
list(2, 2, 2, 2))
5454

55-
# delete the job
55+
# delete the job and its result
5656
deleteJob(jobId)
5757
})

0 commit comments

Comments
 (0)