1
|
|
|
#!/usr/bin/env php |
2
|
|
|
|
|
|
|
|
3
|
|
|
<?php |
|
|
|
|
4
|
|
|
|
5
|
|
|
// This file is part of BOINC. |
6
|
|
|
// https://boinc.berkeley.edu |
7
|
|
|
// Copyright (C) 2025 University of California |
8
|
|
|
// |
9
|
|
|
// BOINC is free software; you can redistribute it and/or modify it |
10
|
|
|
// under the terms of the GNU Lesser General Public License |
11
|
|
|
// as published by the Free Software Foundation, |
12
|
|
|
// either version 3 of the License, or (at your option) any later version. |
13
|
|
|
// |
14
|
|
|
// BOINC is distributed in the hope that it will be useful, |
15
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17
|
|
|
// See the GNU Lesser General Public License for more details. |
18
|
|
|
// |
19
|
|
|
// You should have received a copy of the GNU Lesser General Public License |
20
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
|
22
|
|
|
// - Remind job submitters to retire batches. |
23
|
|
|
// Email a submitter if we haven't emailed them in last week, |
24
|
|
|
// and they have batches aborted > 14 days ago |
25
|
|
|
// or batches completed > 30 days ago. |
26
|
|
|
// - Retire batches after a while. |
27
|
|
|
// Retire a batch if it was completed > 90 days ago |
28
|
|
|
// or it was aborted > 30 days ago |
29
|
|
|
// If we retire any, send the user an email |
30
|
|
|
// |
31
|
|
|
// Run this once a week; the interval determines how often |
32
|
|
|
// users get reminders. |
33
|
|
|
|
34
|
|
|
include_once('../inc/boinc_db.inc'); |
35
|
|
|
include_once('../inc/submit_util.inc'); |
36
|
|
|
include_once('../inc/email.inc'); |
37
|
|
|
include_once('../inc/common_defs.inc'); |
38
|
|
|
|
39
|
|
|
define('COMP_NOTIFY', 30); |
40
|
|
|
define('COMP_LIFE', 90); |
41
|
|
|
define('ABORT_NOTIFY', 14); |
42
|
|
|
define('ABORT_LIFE', 30); |
43
|
|
|
|
44
|
|
|
function send_retire_email($user, $ncomp, $nabort) { |
45
|
|
|
$subject = sprintf('%s job submission reminder', PROJECT); |
46
|
|
|
$text = sprintf( |
47
|
|
|
'This is a reminder from %s. |
48
|
|
|
', |
49
|
|
|
PROJECT |
50
|
|
|
); |
51
|
|
|
if ($ncomp) { |
52
|
|
|
$text .= sprintf( |
53
|
|
|
' |
54
|
|
|
You currently have %d job batches that were completed more than %d days ago. |
55
|
|
|
These batches will automatically be retired %d days after completion.', |
56
|
|
|
$ncomp, COMP_NOTIFY, COMP_LIFE |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
if ($nabort) { |
60
|
|
|
$text .= sprintf( |
61
|
|
|
' |
62
|
|
|
You currently have %d job batches that were aborted more than %d days ago. |
63
|
|
|
These batches will automatically be retired %d days after abortion.', |
64
|
|
|
$nabort, ABORT_NOTIFY, ABORT_LIFE |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
$text .= sprintf( |
68
|
|
|
' |
69
|
|
|
|
70
|
|
|
When a batch is retired, its output files are deleted. |
71
|
|
|
Please download any needed output files, and retire batches: |
72
|
|
|
%s%s |
73
|
|
|
', |
74
|
|
|
master_url(), |
75
|
|
|
'submit.php?action=show_user_batches' |
76
|
|
|
); |
77
|
|
|
echo "reminding $user->name\n"; |
78
|
|
|
send_email($user, $subject, $text); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
function send_retire_emails() { |
82
|
|
|
$uss = BoincUserSubmit::enum(''); |
83
|
|
|
foreach ($uss as $us) { |
84
|
|
|
$user = BoincUser::lookup_id($us->user_id); |
85
|
|
|
if (!$user) continue; |
86
|
|
|
$batches = BoincBatch::enum("user_id=$user->id"); |
87
|
|
|
// transition in-progress to completed |
88
|
|
|
$batches = get_batches_params($batches); |
89
|
|
|
|
90
|
|
|
$ncomp = 0; |
91
|
|
|
$nabort = 0; |
92
|
|
|
$min_comp = time() - COMP_NOTIFY*86400; |
93
|
|
|
$min_abort = time() - ABORT_NOTIFY*86400; |
94
|
|
|
foreach ($batches as $batch) { |
95
|
|
|
switch ($batch->state) { |
96
|
|
|
case BATCH_STATE_COMPLETE: |
97
|
|
|
if ($batch->completion_time < $min_comp) { |
98
|
|
|
$ncomp++; |
99
|
|
|
} |
100
|
|
|
break; |
101
|
|
|
case BATCH_STATE_ABORTED: |
102
|
|
|
if ($batch->completion_time < $min_abort) { |
103
|
|
|
$nabort++; |
104
|
|
|
} |
105
|
|
|
break; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
if ($ncomp || $nabort) { |
109
|
|
|
send_retire_email($user, $ncomp, $nabort); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
function retire_batches() { |
115
|
|
|
$batches = BoincBatch::enum(''); |
116
|
|
|
$batches = get_batches_params($batches); |
117
|
|
|
$users = []; |
118
|
|
|
$min_comp = time() - COMP_LIFE*86400; |
119
|
|
|
$min_abort = time() - ABORT_LIFE*86400; |
120
|
|
|
foreach ($batches as $batch) { |
121
|
|
|
switch ($batch->state) { |
122
|
|
|
case BATCH_STATE_COMPLETE: |
123
|
|
|
if ($batch->completion_time < $min_comp) { |
124
|
|
|
retire_batch($batch); |
125
|
|
|
echo "retire complete $batch->id user $batch->user_id\n"; |
126
|
|
|
$users[] = $batch->user_id; |
127
|
|
|
} |
128
|
|
|
break; |
129
|
|
|
case BATCH_STATE_ABORTED: |
130
|
|
|
if ($batch->completion_time < $min_abort) { |
131
|
|
|
retire_batch($batch); |
132
|
|
|
echo "retire aborted $batch->id user $batch->user_id\n"; |
133
|
|
|
$users[] = $batch->user_id; |
134
|
|
|
} |
135
|
|
|
break; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
$users = array_unique($users); |
139
|
|
|
$subject = sprintf('%s batches retired', PROJECT); |
140
|
|
|
foreach ($users as $id) { |
141
|
|
|
$user = BoincUser::lookup_id($id); |
142
|
|
|
if (!$user) continue; |
143
|
|
|
$text = sprintf( |
144
|
|
|
'Greetings from %s. |
145
|
|
|
|
146
|
|
|
We recently retired one or more of your job batches. |
147
|
|
|
Completed batches are automatically retired after %d days. |
148
|
|
|
Aborted batches are retired after %d days. |
149
|
|
|
|
150
|
|
|
We suggest that you manually retire batches after downloading needed output files. |
151
|
|
|
', |
152
|
|
|
PROJECT, |
153
|
|
|
COMP_LIFE, ABORT_LIFE |
154
|
|
|
); |
155
|
|
|
send_email($user, $subject, $text); |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
retire_batches(); |
160
|
|
|
send_retire_emails(); |
161
|
|
|
?> |
162
|
|
|
|