Skip to content
Snippets Groups Projects
Commit 07edecff authored by Chris Sangwin's avatar Chris Sangwin
Browse files

Add in an explicit timelimit when deploying variants, which exceeds the default 30 seconds.

parent 51b8fe1a
No related branches found
No related tags found
No related merge requests found
...@@ -76,6 +76,15 @@ if (!is_null($undeploy) && $question->deployedseeds) { ...@@ -76,6 +76,15 @@ if (!is_null($undeploy) && $question->deployedseeds) {
$deploy = optional_param('deploymany', null, PARAM_INT); $deploy = optional_param('deploymany', null, PARAM_INT);
$deploytxt = optional_param('deploymany', null, PARAM_TEXT); $deploytxt = optional_param('deploymany', null, PARAM_TEXT);
$starttime = time();
// The number of seconds we devote to deploying before moving on. Prevents system hangging.
// Note, in "safe mode" the set time limit function has no effect.
$maxtime = 25;
if (!ini_get('safe_mode')) {
$maxtime = 180;
set_time_limit($maxtime + 5);
}
if (!is_null($deploy)) { if (!is_null($deploy)) {
if (0 == $deploy) { if (0 == $deploy) {
...@@ -92,7 +101,7 @@ if (!is_null($deploy)) { ...@@ -92,7 +101,7 @@ if (!is_null($deploy)) {
$failedattempts = 0; $failedattempts = 0;
$numberdeployed = 0; $numberdeployed = 0;
while ($failedattempts < $maxfailedattempts && $numberdeployed < $deploy) { while ($failedattempts < $maxfailedattempts && $numberdeployed < $deploy && time() - $starttime < $maxtime) {
// Genrate a new seed. // Genrate a new seed.
$seed = mt_rand(); $seed = mt_rand();
$variantdeployed = false; $variantdeployed = false;
...@@ -147,6 +156,10 @@ if (!is_null($deploy)) { ...@@ -147,6 +156,10 @@ if (!is_null($deploy)) {
$nexturl->param('deployfeedback', stack_string('deploymanysuccess', array('no' => $numberdeployed))); $nexturl->param('deployfeedback', stack_string('deploymanysuccess', array('no' => $numberdeployed)));
$nexturl->param('seed', $seed); $nexturl->param('seed', $seed);
if (time() - $starttime >= $maxtime) {
$nexturl->param('deployfeedbackerr', stack_string('deployoutoftime', array('time' => time() - $starttime)));
redirect($nexturl);
}
if ($failedattempts >= $maxfailedattempts) { if ($failedattempts >= $maxfailedattempts) {
$nexturl->param('deployfeedbackerr', stack_string('deploymanynonew')); $nexturl->param('deployfeedbackerr', stack_string('deploymanynonew'));
} }
......
...@@ -432,6 +432,7 @@ $string['deploytoomanyerror'] = 'STACK will try to deploy up to at most 100 new ...@@ -432,6 +432,7 @@ $string['deploytoomanyerror'] = 'STACK will try to deploy up to at most 100 new
$string['deploymanynonew'] = 'Too many repeated existing question notes were generated.'; $string['deploymanynonew'] = 'Too many repeated existing question notes were generated.';
$string['deploymanynotes'] = 'Note, STACK will give up if there are 10 failed attempts to generate a new question note, or when one question test fails.'; $string['deploymanynotes'] = 'Note, STACK will give up if there are 10 failed attempts to generate a new question note, or when one question test fails.';
$string['deploymanysuccess'] = 'Number of new variants successfully created, tested and deployed: {$a->no}.'; $string['deploymanysuccess'] = 'Number of new variants successfully created, tested and deployed: {$a->no}.';
$string['deployoutoftime'] = 'Time limit exceeded by using approx {$a->time} seconds. Please try again to deploy more.';
$string['deployremoveall'] = 'Undeploy all variants: '; $string['deployremoveall'] = 'Undeploy all variants: ';
$string['deploytestall'] = 'Run all tests on all deployed variants (slow): '; $string['deploytestall'] = 'Run all tests on all deployed variants (slow): ';
$string['editingtestcase'] = 'Editing test case {$a->no} for question {$a->question}'; $string['editingtestcase'] = 'Editing test case {$a->no} for question {$a->question}';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment