-
Notifications
You must be signed in to change notification settings - Fork 9
/
monitor.R
81 lines (80 loc) · 2.33 KB
/
monitor.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
test_that("SGE monitor terminate one job at a time", {
controller <- crew_controller_sge(
name = "my_workflow",
workers = 2L,
seconds_idle = 600,
options_cluster = crew_options_sge(
script_lines = paste0("module load R/", getRversion()),
verbose = TRUE
)
)
on.exit(controller$terminate())
controller$start()
controller$launch(n = 2L)
names <- vapply(
controller$launcher$workers$handle,
function(handle) handle$name,
FUN.VALUE = character(1L)
)
monitor <- crew_monitor_sge(verbose = TRUE)
crew::crew_retry(
~ all(names %in% monitor$jobs()$name),
seconds_interval = 1,
seconds_timeout = 60,
message = "could not submit jobs"
)
jobs <- monitor$jobs()
jobs <- jobs[jobs$name %in% names, ]
expect_equal(nrow(jobs), 2L)
expect_true(is.character(jobs$job_number))
expect_false(anyNA(jobs$job_number))
expect_true(all(nzchar(jobs$job_number)))
monitor$terminate(jobs = jobs$job_number)
crew::crew_retry(
~ !any(jobs$job_number %in% monitor$jobs()$job_number),
seconds_interval = 1,
seconds_timeout = 60,
message = "could not terminate jobs"
)
expect_false(any(jobs$job_number %in% monitor$jobs()$job_number))
})
test_that("THIS TEST DELETES ALL USER JOBS! USE WITH CAUTION!", {
controller <- crew_controller_sge(
name = "my_workflow",
workers = 2L,
seconds_idle = 600,
options_cluster = crew_options_sge(
script_lines = paste0("module load R/", getRversion()),
verbose = TRUE
)
)
on.exit(controller$terminate())
controller$start()
controller$launch(n = 2L)
names <- vapply(
controller$launcher$workers$handle,
function(handle) handle$name,
FUN.VALUE = character(1L)
)
monitor <- crew_monitor_sge(verbose = TRUE)
crew::crew_retry(
~ all(names %in% monitor$jobs()$name),
seconds_interval = 1,
seconds_timeout = 60,
message = "could not submit jobs"
)
jobs <- monitor$jobs()
jobs <- jobs[jobs$name %in% names, ]
expect_equal(nrow(jobs), 2L)
expect_true(is.character(jobs$job_number))
expect_false(anyNA(jobs$job_number))
expect_true(all(nzchar(jobs$job_number)))
monitor$terminate(all = TRUE)
crew::crew_retry(
~ nrow(monitor$jobs()) < 1L,
seconds_interval = 1,
seconds_timeout = 60,
message = "could not terminate jobs"
)
expect_lt(nrow(monitor$jobs()), 1L)
})