Skip to content

Commit

Permalink
Merge pull request #167 from cyriltata/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
cyriltata committed Jul 13, 2015
2 parents 019053a + 7925715 commit 2aa03a5
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 24 deletions.
11 changes: 5 additions & 6 deletions Model/RunUnit.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,19 +572,18 @@ public function getParsedBody($source, $email_embed = false) {
if ($this->called_by_cron) {
return false; // don't regenerate once we once had a report for this feedback, if it's only the cronjob
}
$opencpu_url = rtrim($opencpu_url,"/") . $email_embed ? '' : '/R/.val/';

$opencpu_url = rtrim($opencpu_url, "/") . $email_embed ? '' : '/R/.val/';
$format = ($email_embed ? "" : "json");
$session = opencpu_get($opencpu_url, $format , null, true);
}



// If there no session or old session (from aquired url) has an error for some reason, then get a new one for current request
if (!isset($session) || empty($session) || $session->hasError()) {
if (empty($session) || $session->hasError()) {
$ocpu_vars = $this->getUserDataInRun($source);
$session = $email_embed ? opencpu_knitemail($source, $ocpu_vars, '', true) : opencpu_knitdisplay($source, $ocpu_vars, true);
}

// At this stage we are sure to have an OpenCPU_Session in $session. If there is an error in the session return FALSE
if(empty($session)) {
alert('OpenCPU is probably down or inaccessible.', 'alert-danger');
Expand Down
2 changes: 1 addition & 1 deletion Model/Survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function create($options) {

public function render() {
global $js;
$js = (isset($js) ? $js : '') . '<script src="' . WEBROOT . 'assets/' . (DEBUG ? 'js' : 'minified') . '/survey.js"></script>';
$js = (isset($js) ? $js : '') . '<script src="' . WEBROOT . 'assets/' . (DEBUG ? 'js' : 'minified') . '/survey.js?v='.VERSION.'"></script>';

$ret = '
<div class="row study-' . $this->id . ' study-name-'. $this->name .'">
Expand Down
27 changes: 15 additions & 12 deletions View/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,26 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

<link rel="stylesheet" type="text/css" href="<?= WEBROOT ?>assets/lib/bower<?=DEBUG?"":".min"?>.css" />
<link rel="stylesheet" type="text/css" href="<?= WEBROOT ?>assets/lib/bower<?= DEBUG ? "" : ".min" ?>.css?v=<?php echo VERSION; ?>" />

<?php echo isset($css) ? $css : '' ?>
<script type="text/javascript" src="<?= WEBROOT ?>assets/<?=DEBUG?"lib":"minified"?>/bower.js"></script>

<script type="text/javascript" src="<?= WEBROOT ?>assets/<?= DEBUG ? "lib" : "minified" ?>/bower.js?v=<?php echo VERSION; ?>"></script>
<?php echo isset($js) ? $js : '' ?>
<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-45924096-1']);
_gaq.push(['_trackPageview']);
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-45924096-1']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
(function () {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();

</script>
</head>
Expand Down
9 changes: 5 additions & 4 deletions bin/cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

require_once dirname(__FILE__) . '/../define_root.php';

// Set maximum execution time to 6 minutes as cron runs every 7 minutes. (There should be better way to do this)
// Set maximum execution time to 9 minutes as cron runs every 10 minutes. (There should be better way to do this)
$start_time = microtime(true);
$max_exec_time = 6 * 60;
$max_exec_time = (int)Config::get('cron.ttl_cron') * 60;
$intercept_if_expired = (int)Config::get('cron.intercept_if_expired');
set_time_limit($max_exec_time);

// Define vars
Expand Down Expand Up @@ -78,7 +79,7 @@ function cron_interrupt($signo) {
cron_log("Cron overlapped. Started: $started, Overlapped: $start_date");

// hack to delete $lockfile if cron hangs for more that 30 mins
if ((strtotime($started) + (30 * 60)) < time()) {
if ((strtotime($started) + ((int)Config::get('cron.ttl_lockfile') * 60)) < time()) {
cron_log("Forced delete of $lockfile");
unlink($lockfile);
}
Expand Down Expand Up @@ -175,7 +176,7 @@ function cron_interrupt($signo) {

//echo $msg . "<br />";
cron_log(strip_tags($msg), true);
if (microtime(true) - $start_time > $max_exec_time) {
if ($intercept_if_expired && microtime(true) - $start_time > $max_exec_time) {
throw new Exception("Cron Intercepted! Started at: $start_date, Intercepted at: " . date('r'));
}
endforeach;
Expand Down
14 changes: 13 additions & 1 deletion config_default/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Formr.org configuration
*/

$settings['version'] = 'v0.7.1';

// Database Settings
$settings['database'] = array(
'datasource' => 'Database/Mysql',
Expand Down Expand Up @@ -73,4 +75,14 @@
//'testing' => true
);

$settings['referrer_codes'] = array();
$settings['referrer_codes'] = array();

// Cron settings
$settings['cron'] = array(
// maximum time to live for a 'cron session' in minutes
'ttl_cron' => 15,
// maximum time to live for log file in minutes
'ttl_lockfile' => 30,
// Should cron be intercepted if session time is exceeded?
'intercept_if_expired' => false,
);
1 change: 1 addition & 0 deletions define_root.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ function define_webroot($settings = array()) {
define('SSL', $protocol === "https://");
define('RUNROOT', WEBROOT);
define('DEBUG', Config::get('display_errors'));
define('VERSION', Config::get('version'));
}
define_webroot($settings);

0 comments on commit 2aa03a5

Please sign in to comment.