@@ -204,20 +204,7 @@ public function execute($sourcecode, $language, $input, $files = null, $params =
204
204
$ this ->apikey = $ params ['jobeapikey ' ];
205
205
}
206
206
}
207
- // QUESTION: Do we need this when using cached result?
208
- $ this ->currentjobid = sprintf ('%08x ' , mt_rand ());
209
207
210
- // Create a single curl object here, with support for cookies, and use it for all requests.
211
- // This supports Jobe back-ends that use cookies for sticky load-balancing.
212
- // Make a place to store the cookies.
213
- make_temp_directory ('qtype_coderunner ' );
214
- $ cookiefile = $ CFG ->tempdir . '/qtype_coderunner/session_cookies_ ' . $ this ->currentjobid . '.txt ' ;
215
-
216
- $ curl = new curl ();
217
- $ curl ->setopt ([
218
- 'CURLOPT_COOKIEJAR ' => $ cookiefile ,
219
- 'CURLOPT_COOKIEFILE ' => $ cookiefile ,
220
- ]);
221
208
222
209
$ cache = cache::make ('qtype_coderunner ' , 'coderunner_grading_cache ' );
223
210
$ runresult = null ;
@@ -239,7 +226,20 @@ public function execute($sourcecode, $language, $input, $files = null, $params =
239
226
}
240
227
}
241
228
242
- if (!$ runresult ) { // if cache read failed regrade to be safe
229
+ if (!$ runresult ) { // if cache read failed regrade, to be safe.
230
+ $ this ->currentjobid = sprintf ('%08x ' , mt_rand ());
231
+
232
+ // Create a single curl object here, with support for cookies, and use it for all requests.
233
+ // This supports Jobe back-ends that use cookies for sticky load-balancing.
234
+ // Make a place to store the cookies.
235
+ make_temp_directory ('qtype_coderunner ' );
236
+ $ cookiefile = $ CFG ->tempdir . '/qtype_coderunner/session_cookies_ ' . $ this ->currentjobid . '.txt ' ;
237
+
238
+ $ curl = new curl ();
239
+ $ curl ->setopt ([
240
+ 'CURLOPT_COOKIEJAR ' => $ cookiefile ,
241
+ 'CURLOPT_COOKIEFILE ' => $ cookiefile ,
242
+ ]);
243
243
$ postbody = ['run_spec ' => $ runspec ];
244
244
// Try submitting the job. If we get a 404, try again after
245
245
// putting all the files on the server. Anything else is an error.
@@ -256,8 +256,8 @@ public function execute($sourcecode, $language, $input, $files = null, $params =
256
256
}
257
257
}
258
258
259
- // Delete the cookie file.
260
- unlink ($ cookiefile );
259
+ // Delete the cookie file.
260
+ unlink ($ cookiefile );
261
261
262
262
$ runresult = [];
263
263
$ runresult ['sandboxinfo ' ] = [
@@ -269,8 +269,8 @@ public function execute($sourcecode, $language, $input, $files = null, $params =
269
269
if (
270
270
!$ okresponse // If it's not an OK response...
271
271
|| !is_object ($ this ->response ) // ... or there's any sort of broken ...
272
- || !isset ($ this ->response ->outcome )
273
- ) { // ... communication with server.
272
+ || !isset ($ this ->response ->outcome ) // ... communication with server.
273
+ ) {
274
274
// Return with errorcode set and as much extra info as possible in stderr.
275
275
$ errorcode = $ okresponse ? self ::UNKNOWN_SERVER_ERROR : $ this ->get_error_code ($ httpcode );
276
276
$ this ->currentjobid = null ;
@@ -295,7 +295,7 @@ public function execute($sourcecode, $language, $input, $files = null, $params =
295
295
// Got a useable result from Jobe server so cache it if required.
296
296
if (WRITE_TO_CACHE ) {
297
297
$ key = hash ("md5 " , serialize ($ runspec ));
298
- $ cache ->set ($ key , $ runresult ); // set serializes the result, get will unserialize.
298
+ $ cache ->set ($ key , $ runresult ); // Set serializes the result, get will unserialize.
299
299
// echo 'CACHE WRITE for ---> ' . $key . '<br>';
300
300
}
301
301
}
0 commit comments