Skip to content

Commit

Permalink
Fix #39, Idle timeout abfangen
Browse files Browse the repository at this point in the history
  • Loading branch information
BugBuster1701 committed Sep 7, 2020
1 parent 515d5db commit 14073a2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
4 changes: 1 addition & 3 deletions src/EventListener/DataContainer/SaveCallbackListener.php
Expand Up @@ -79,16 +79,14 @@ public function onSaveCallbackDayofweek($dayofweek, DataContainer $dc): string
return $dayofweek;
}


/**
* Check Crontab Values via \Cron\CronExpression
* Check Crontab Values via \Cron\CronExpression.
*
* @param string $minute
* @param string $hour
* @param string $dayofmonth
* @param string $month
* @param string $dayofweek
* @return boolean
*/
protected function checkCrontabValues($minute, $hour, $dayofmonth, $month, $dayofweek): bool
{
Expand Down
8 changes: 5 additions & 3 deletions src/Resources/contao/classes/CronRequest.php
Expand Up @@ -2,6 +2,7 @@

namespace BugBuster\Cron;

use Contao\System;
use Symfony\Component\HttpClient\HttpClient;

/**
Expand Down Expand Up @@ -47,7 +48,7 @@ class CronRequest
*/
public function __construct(string $url)
{
\System::loadLanguageFile('tl_crontab');
System::loadLanguageFile('tl_crontab');

$this->responseBody = '';
$this->url = $url;
Expand All @@ -72,14 +73,15 @@ public function __construct(string $url)
public function get()
{
try {
$response = $this->httpClient->request('GET', $this->url, array('timeout' => 3));
$response = $this->httpClient->request('GET', $this->url, array('timeout' => 5));
$this->responseBody = $response->getContent();
} catch (\Throwable $t) {
$this->responseBody = "<span style='color:red;'>Request Exception:<br>".$t->getMessage()."</span>";
$this->responseStatusCode = 500;

return $this->responseStatusCode;
}
$this->responseBody = $response->getContent();

$this->responseStatusCode = $response->getStatusCode();

return $this->responseStatusCode;
Expand Down
11 changes: 5 additions & 6 deletions src/Resources/contao/controllers/ContaoFrontendController.php
Expand Up @@ -13,7 +13,6 @@
use Contao\Database;
use Contao\Environment;
use Psr\Log\LogLevel;
use Symfony\Bundle\FrameworkBundle\Routing\Router;
use Symfony\Component\HttpFoundation\Response;

/**
Expand Down Expand Up @@ -86,7 +85,7 @@ public function runJobs()
$currtime = time();

// process cron list
$q = \Database::getInstance()->prepare("SELECT * FROM `tl_crontab`
$q = Database::getInstance()->prepare("SELECT * FROM `tl_crontab`
WHERE `enabled`='1'
AND (
(`nextrun`>0 and `nextrun`<?)
Expand All @@ -107,7 +106,7 @@ public function runJobs()
if (!$locked)
{
// ensure exclusive access
$ql = \Database::getInstance()->prepare("SELECT get_lock('cronlock',0) AS lockstate")->execute();
$ql = Database::getInstance()->prepare("SELECT get_lock('cronlock',0) AS lockstate")->execute();
if (!$ql->next() || !(int) ($ql->lockstate))
{
return $objResponse;
Expand Down Expand Up @@ -147,7 +146,7 @@ public function runJobs()
'scheduled' => $currtime
);
}
\Database::getInstance()->prepare("UPDATE `tl_crontab` %s WHERE id=?")
Database::getInstance()->prepare("UPDATE `tl_crontab` %s WHERE id=?")
->set($dataset)
->execute($q->id);
} // if
Expand Down Expand Up @@ -177,7 +176,7 @@ public function runJobs()
'nextrun' => $this->getNextRun($q),
'scheduled' => $currtime
);
\Database::getInstance()->prepare("UPDATE `tl_crontab` %s WHERE id=?")
Database::getInstance()->prepare("UPDATE `tl_crontab` %s WHERE id=?")
->set($dataset)
->execute($q->id);
} // if
Expand All @@ -186,7 +185,7 @@ public function runJobs()
// release lock
if ($locked)
{
\Database::getInstance()->prepare("SELECT release_lock('cronlock')")->execute();
Database::getInstance()->prepare("SELECT release_lock('cronlock')")->execute();
}

return $objResponse;
Expand Down

0 comments on commit 14073a2

Please sign in to comment.