Skip to content

Commit eb9aca5

Browse files
committed
Code tidying.
1 parent 9406608 commit eb9aca5

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

Diff for: classes/jobesandbox.php

+19-19
Original file line numberDiff line numberDiff line change
@@ -204,20 +204,7 @@ public function execute($sourcecode, $language, $input, $files = null, $params =
204204
$this->apikey = $params['jobeapikey'];
205205
}
206206
}
207-
// QUESTION: Do we need this when using cached result?
208-
$this->currentjobid = sprintf('%08x', mt_rand());
209207

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-
]);
221208

222209
$cache = cache::make('qtype_coderunner', 'coderunner_grading_cache');
223210
$runresult = null;
@@ -239,7 +226,20 @@ public function execute($sourcecode, $language, $input, $files = null, $params =
239226
}
240227
}
241228

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+
]);
243243
$postbody = ['run_spec' => $runspec];
244244
// Try submitting the job. If we get a 404, try again after
245245
// 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 =
256256
}
257257
}
258258

259-
// Delete the cookie file.
260-
unlink($cookiefile);
259+
// Delete the cookie file.
260+
unlink($cookiefile);
261261

262262
$runresult = [];
263263
$runresult['sandboxinfo'] = [
@@ -269,8 +269,8 @@ public function execute($sourcecode, $language, $input, $files = null, $params =
269269
if (
270270
!$okresponse // If it's not an OK response...
271271
|| !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+
) {
274274
// Return with errorcode set and as much extra info as possible in stderr.
275275
$errorcode = $okresponse ? self::UNKNOWN_SERVER_ERROR : $this->get_error_code($httpcode);
276276
$this->currentjobid = null;
@@ -295,7 +295,7 @@ public function execute($sourcecode, $language, $input, $files = null, $params =
295295
// Got a useable result from Jobe server so cache it if required.
296296
if (WRITE_TO_CACHE) {
297297
$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.
299299
// echo 'CACHE WRITE for ---> ' . $key . '<br>';
300300
}
301301
}

0 commit comments

Comments
 (0)