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

Commit 25cd325

Browse files
committed
rename jobAutoDelete to autoDeleteJob to workaround R bugs and update docs
1 parent a9eec76 commit 25cd325

File tree

8 files changed

+121
-37
lines changed

8 files changed

+121
-37
lines changed

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ export(listStorageFiles)
1717
export(makeCluster)
1818
export(registerDoAzureParallel)
1919
export(resizeCluster)
20+
export(setAutoDeleteJob)
2021
export(setChunkSize)
2122
export(setCredentials)
2223
export(setHttpTraffic)
23-
export(setJobAutoDelete)
2424
export(setReduce)
2525
export(setVerbose)
2626
export(stopCluster)

R/doAzureParallel.R

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

76-
#' Specify whether to delete job/jobresult after asychronous job is completed.
76+
#' Specify whether to delete job and its result after asychronous job is completed.
7777
#'
7878
#' @param value boolean of TRUE or FALSE
7979
#'
8080
#' @examples
81-
#' setJobAutoDelete(FALSE)
81+
#' setAutoDeleteJob(FALSE)
8282
#' @export
83-
setJobAutoDelete <- function(value = TRUE) {
83+
setAutoDeleteJob <- function(value = TRUE) {
8484
if (!is.logical(value))
85-
stop("setJobAutoDelete requires a boolean argument")
85+
stop("setAutoDeleteJob requires a boolean argument")
8686

87-
assign("jobAutoDelete", value, envir = .doAzureBatchGlobals)
87+
assign("autoDeleteJob", value, envir = .doAzureBatchGlobals)
8888
}
8989

9090
#' Apply reduce function on a group of iterations of the foreach loop together per task.
@@ -247,15 +247,15 @@ setHttpTraffic <- function(value = FALSE) {
247247
}
248248

249249
# by default, delete both job and job result after synchronous job is completed
250-
jobAutoDelete <- TRUE
250+
autoDeleteJob <- TRUE
251251

252-
if (exists("jobAutoDelete", envir = .doAzureBatchGlobals)) {
253-
jobAutoDelete <- get("jobAutoDelete", envir = .doAzureBatchGlobals)
252+
if (exists("autoDeleteJob", envir = .doAzureBatchGlobals)) {
253+
autoDeleteJob <- get("autoDeleteJob", envir = .doAzureBatchGlobals)
254254
}
255255

256-
if (!is.null(obj$options$azure$jobAutoDelete) &&
257-
is.logical(obj$options$azure$jobAutoDelete)) {
258-
jobAutoDelete <- obj$options$azure$jobAutoDelete
256+
if (!is.null(obj$options$azure$autoDeleteJob) &&
257+
is.logical(obj$options$azure$autoDeleteJob)) {
258+
autoDeleteJob <- obj$options$azure$autoDeleteJob
259259
}
260260

261261
inputs <- FALSE
@@ -585,7 +585,7 @@ setHttpTraffic <- function(value = FALSE) {
585585

586586
numberOfFailedTasks <- sum(unlist(failTasks))
587587

588-
if (numberOfFailedTasks > 0 && jobAutoDelete == FALSE) {
588+
if (numberOfFailedTasks > 0 && autoDeleteJob == FALSE) {
589589
.createErrorViewerPane(id, failTasks)
590590
}
591591

@@ -607,15 +607,18 @@ setHttpTraffic <- function(value = FALSE) {
607607
fill = TRUE)
608608

609609
# delete job from batch service and job result from storage blob
610-
if (jobAutoDelete) {
610+
if (autoDeleteJob) {
611611
deleteJob(id)
612612
}
613613

614614
if (identical(obj$errorHandling, "stop") &&
615615
!is.null(errorValue)) {
616-
msg <- sprintf("task %d failed - '%s'",
617-
errorIndex,
618-
conditionMessage(errorValue))
616+
msg <-
617+
sprintf(
618+
"task %d failed - '%s'.\r\nBy default job and its result is deleted after run is over, use setAutoDeleteJob(FALSE) or autoDeleteJob = FALSE option to keep them for investigation.",
619+
errorIndex,
620+
conditionMessage(errorValue)
621+
)
619622
stop(simpleError(msg, call = expr))
620623
}
621624
else {

docs/23-persistent-storage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ By default, *wait* is set to TRUE. This blocks the R session. By setting *wait*
2222

2323
## Getting results from storage
2424

25-
When the user is ready to get their results in a new session, the user use the following command:
25+
When the user is ready to get their results in a new session, the user uses the following command:
2626

2727
```R
2828
my_job_id <- "my_unique_job_id"

docs/40-troubleshooting.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,18 @@ This issue is due to certain compiler flags not available in the default version
6767
Since doAzureParallel uses Microsoft R Open version 3.3 as the default version of R, it will automatically try to pull package from [MRAN](https://mran.microsoft.com/) rather than CRAN. This is a big benefit when wanting to use a constant version of a package but does not always contain references to the latest versions. To use a specific version from CRAN or a different MRAN snapshot date, use the [command line](./30-customize-cluster.md#running-commands-when-the-cluster-starts) in the cluster configuration to manually install the packages you need.
6868

6969
## Viewing files from Azure Storage
70-
In every foreach run, the job will push its logs into Azure Storage that can be fetched by the user. For more information on reading log files, check out [managing storage](./41-managing-storage-via-R.md).
70+
In every foreach run, the job will push its logs into Azure Storage that can be fetched by the user. For more information on reading log files, check out [managing storage](./41-managing-storage-via-R.md).
71+
72+
By default, when wait is set to TRUE, job and its result is automatically deleted after the run is completed. To keep the job and its result for investigation purpose, you can set a global environment setting or specify an option in foreach loop to keep it.
73+
74+
```R
75+
# This will set a global setting to keep job and its result after run is completed.
76+
setAutoDeleteJob(FALSE)
77+
78+
# This will keep job and its result at each job level after run is completed.
79+
options <- list(autoDeleteJob = FALSE)
80+
foreach::foreach(i = 1:4, .options.azure = opt) %dopar% { ... }
81+
```
7182

7283
## Viewing files directly from compute node
7384
Cluster setup logs are not persisted. `getClusterFile` function will fetch any files including stdout and stderr log files in the cluster. This is particularly useful for users that utilizing [customize script](./30-customize-cluster.md) on their nodes and installing specific [packages](./20-package-management.md).

docs/42-faq.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ Yes. The [command line](./30-customize-cluster.md#running-commands-when-the-clus
1919
No. doAzureParallel is built on top of the Linux CentOS distribution and will not work with Windows-specific packages.
2020

2121
## Why am I getting the error: could not find function "startsWith"?
22-
doAzureParallel requires you to run R 3.3 or greater on you local machine.
22+
doAzureParallel requires you to run R 3.3 or greater on you local machine.
23+
24+
## My job failed but I can't find my job and its result?
25+
if you set wait = TRUE, job and its result is automatically deleted, to keep them for investigation purpose, you can set global option using setAutoDeleteJob(FALSE), or use autoDeleteJob option at foreach level.

man/setAutoDeleteJob.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.

man/setJobAutoDelete.Rd

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Run this test for users to make sure the autodeletejob feature
2+
# of doAzureParallel is still working
3+
context("auto delete job scenario test")
4+
test_that("auto delete job as foreach option test", {
5+
testthat::skip("Live test")
6+
testthat::skip_on_travis()
7+
credentialsFileName <- "credentials.json"
8+
clusterFileName <- "cluster.json"
9+
10+
doAzureParallel::generateCredentialsConfig(credentialsFileName)
11+
doAzureParallel::generateClusterConfig(clusterFileName)
12+
13+
doAzureParallel::setCredentials(credentialsFileName)
14+
cluster <- doAzureParallel::makeCluster(clusterFileName)
15+
doAzureParallel::registerDoAzureParallel(cluster)
16+
17+
# use autoDeleteJob flag to keep the job and its result
18+
'%dopar%' <- foreach::'%dopar%'
19+
res <-
20+
foreach::foreach(i = 1:10,
21+
.options.azure = list(autoDeleteJob = FALSE)) %dopar% {
22+
i
23+
}
24+
25+
testthat::expect_equal(length(res),
26+
10)
27+
28+
for (i in 1:10) {
29+
testthat::expect_equal(res[[i]],
30+
i)
31+
}
32+
33+
# find the job id from the output of above command and call deleteJob(jobId) when you no longer need the job and its result
34+
})
35+
36+
test_that("auto delete job as global setting test", {
37+
testthat::skip("Live test")
38+
testthat::skip_on_travis()
39+
credentialsFileName <- "credentials.json"
40+
clusterFileName <- "cluster.json"
41+
42+
doAzureParallel::generateCredentialsConfig(credentialsFileName)
43+
doAzureParallel::generateClusterConfig(clusterFileName)
44+
45+
doAzureParallel::setCredentials(credentialsFileName)
46+
cluster <- doAzureParallel::makeCluster(clusterFileName)
47+
doAzureParallel::registerDoAzureParallel(cluster)
48+
49+
# set autoDeleteJob flag to FALSE to keep the job and its result
50+
setAutoDeleteJob(FALSE)
51+
52+
'%dopar%' <- foreach::'%dopar%'
53+
res <-
54+
foreach::foreach(i = 1:10) %dopar% {
55+
i
56+
}
57+
58+
testthat::expect_equal(length(res),
59+
10)
60+
61+
for (i in 1:10) {
62+
testthat::expect_equal(res[[i]],
63+
i)
64+
}
65+
66+
# find the job id from the output of above command and call deleteJob(jobId) when you no longer need the job and its result
67+
})

0 commit comments

Comments
 (0)