@@ -78,7 +78,7 @@ function has_submit_access($user, $app_id) {
78
78
function has_admin_access ($ user , $ app_id ) {
79
79
$ us = BoincUserSubmit::lookup_userid ($ user ->id );
80
80
if (!$ us ) return false ;
81
- if ($ us ->admin_all ) return true ;
81
+ if ($ us ->manage_all ) return true ;
82
82
$ usa = BoincUserSubmitApp::lookup ("user_id= $ user ->id and app_id= $ app_id " );
83
83
if (!$ usa ) return false ;
84
84
return $ usa ->manage ;
@@ -126,11 +126,23 @@ function delete_remote_submit_user($user) {
126
126
BoincUserSubmitApp::delete_user ($ user ->id );
127
127
}
128
128
129
-
130
- // given its WUs, compute progress of a batch
131
- // (fraction done, est completion time etc.)
132
- // NOTE: this is inefficient because we need all the WUs.
133
- // it could be done by server components
129
+ // given its WUs, compute parameters of a batch:
130
+ // credit_canonical: credit granted to canonical instances
131
+ // fraction_done: frac of jobs that are done (success or failed)
132
+ // state: whether complete (all jobs done)
133
+ // completion_time: if newly complete
134
+ // nerror_jobs: # of failed jobs
135
+ // Update the above in DB.
136
+ // Also compute (not in DB):
137
+ // njobs_success: # of jobs with canonical instance
138
+ // njobs_in_prog: # of jobs not success or fail,
139
+ // and at least one result in progress
140
+ //
141
+ // return the batch object, with these values
142
+ //
143
+ // NOTE: this involves reading the batch's WUs and results,
144
+ // which could be inefficient for huge batches.
145
+ // It could instead be done by server components
134
146
// (transitioner, validator etc.) as jobs complete or time out
135
147
//
136
148
// TODO: update est_completion_time
@@ -141,51 +153,61 @@ function get_batch_params($batch, $wus) {
141
153
//
142
154
return $ batch ;
143
155
}
156
+ if (!$ wus ) {
157
+ if ($ batch ->njobs ) {
158
+ $ batch ->update ('njobs=0 ' );
159
+ $ batch ->njobs = 0 ;
160
+ }
161
+ return $ batch ;
162
+ }
163
+
164
+ // make list of WU IDs with an in-progress result
165
+ $ res_in_prog = BoincResult::enum (
166
+ sprintf ('batch=%d and server_state<>%d ' ,
167
+ $ batch ->id , RESULT_SERVER_STATE_IN_PROGRESS
168
+ )
169
+ );
170
+ $ wus_in_prog = [];
171
+ foreach ($ res_in_prog as $ res ) {
172
+ $ wus_in_prog [$ res ->workunitid ] = true ;
173
+ }
174
+
144
175
$ fp_total = 0 ;
145
176
$ fp_done = 0 ;
146
177
$ completed = true ;
147
178
$ batch ->nerror_jobs = 0 ;
148
179
$ batch ->credit_canonical = 0 ;
180
+ $ njobs_success = 0 ;
181
+ $ njobs_in_prog = 0 ;
149
182
foreach ($ wus as $ wu ) {
150
183
$ fp_total += $ wu ->rsc_fpops_est ;
151
184
if ($ wu ->canonical_resultid ) {
152
185
$ fp_done += $ wu ->rsc_fpops_est ;
186
+ $ njobs_success ++;
153
187
$ batch ->credit_canonical += $ wu ->canonical_credit ;
154
188
} else if ($ wu ->error_mask ) {
155
189
$ batch ->nerror_jobs ++;
156
190
} else {
157
191
$ completed = false ;
192
+ if (array_key_exists ($ wu ->id , $ wus_in_prog )) {
193
+ $ njobs_in_prog ++;
194
+ }
158
195
}
159
196
}
160
- if ( $ fp_total ) {
161
- $ batch ->fraction_done = $ fp_done / $ fp_total ;
162
- }
197
+ $ njobs = count ( $ wus );
198
+ $ batch ->njobs = $ njobs ;
199
+ $ batch -> fraction_done = ( $ njobs_success + $ batch -> nerror_jobs )/ $ batch -> njobs ;
163
200
if ($ completed && $ batch ->state == BATCH_STATE_IN_PROGRESS ) {
164
201
$ batch ->state = BATCH_STATE_COMPLETE ;
165
202
$ batch ->completion_time = time ();
166
203
}
167
- $ batch ->update ("fraction_done = $ batch ->fraction_done , nerror_jobs = $ batch ->nerror_jobs , state= $ batch ->state , completion_time = $ batch ->completion_time , credit_canonical = $ batch ->credit_canonical " );
204
+ $ batch ->update ("fraction_done = $ batch ->fraction_done , nerror_jobs = $ batch ->nerror_jobs , state= $ batch ->state , completion_time = $ batch ->completion_time , credit_canonical = $ batch ->credit_canonical , njobs= $ njobs " );
168
205
169
- $ batch ->credit_estimate = flops_to_credit ($ fp_total );
206
+ $ batch ->njobs_success = $ njobs_success ;
207
+ $ batch ->njobs_in_prog = $ njobs_in_prog ;
170
208
return $ batch ;
171
209
}
172
210
173
- // get the number of WUs for which we've sent at least 1 instance
174
- // TODO: do this more efficiently (single query)
175
- //
176
- function wus_nsent ($ wus ) {
177
- $ n = 0 ;
178
- foreach ($ wus as $ wu ) {
179
- $ res = BoincResult::enum (
180
- sprintf ('workunitid=%d and server_state<>%d ' ,
181
- $ wu ->id , RESULT_SERVER_STATE_UNSENT
182
- )
183
- );
184
- if (count ($ res ) > 0 ) $ n ++;
185
- }
186
- return $ n ;
187
- }
188
-
189
211
// get the physical names of a result's output files.
190
212
//
191
213
function get_outfile_phys_names ($ result ) {
0 commit comments