本文整理匯總了PHP中Cron::setEnablePreventOverlapping方法的典型用法代碼示例。如果您正苦於以下問題:PHP Cron::setEnablePreventOverlapping方法的具體用法?PHP Cron::setEnablePreventOverlapping怎麽用?PHP Cron::setEnablePreventOverlapping使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Cron
的用法示例。
在下文中一共展示了Cron::setEnablePreventOverlapping方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testPreventOverlapping
/**
* Test the prevent job overlapping functionality
*
* @covers \Liebig\Cron\Cron::run
* @covers \Liebig\Cron\Cron::setEnablePreventOverlapping
* @covers \Liebig\Cron\Cron::setDisablePreventOverlapping
* @covers \Liebig\Cron\Cron::isPreventOverlapping
*/
public function testPreventOverlapping()
{
// Disable database logging because we need this later
Cron::setDatabaseLogging(false);
// Getting storage path with Laravel3 fallback
$storagePath = "";
if (function_exists('storage_path')) {
$storagePath = storage_path();
} else {
if (function_exists('path')) {
$storagePath = path('storage');
} else {
throw new RuntimeException('Could not find the path to Laravels storage directory.');
}
}
// We disabled this at startup -> have a look at the setDefaultConfigValues method
$this->assertEquals(false, Cron::isPreventOverlapping());
// Enabling prevention
Cron::setEnablePreventOverlapping();
$this->assertEquals(true, Cron::isPreventOverlapping());
// Disabling prevention
Cron::setDisablePreventOverlapping();
$this->assertEquals(false, Cron::isPreventOverlapping());
// Sorry, for windows 7 servers unlink and touch does not work
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
return;
}
// Create a example job which writes to the $lockfileExists variable if a lock file exists
$lockfileExists;
Cron::add('testlockfile', "* * * * *", function () use(&$lockfileExists, $storagePath) {
if (file_exists($storagePath . DIRECTORY_SEPARATOR . 'cron.lock')) {
$lockfileExists = true;
} else {
$lockfileExists = false;
}
});
Cron::run();
$this->assertEquals(false, $lockfileExists);
$this->assertEquals(false, file_exists($storagePath . DIRECTORY_SEPARATOR . 'cron.lock'));
$lockfileExists = "";
Cron::setEnablePreventOverlapping();
$this->assertEquals(true, Cron::isPreventOverlapping());
Cron::run();
$this->assertEquals(true, $lockfileExists);
$this->assertEquals(false, file_exists($storagePath . DIRECTORY_SEPARATOR . 'cron.lock'));
// Simulate two run calls at the same time
touch($storagePath . DIRECTORY_SEPARATOR . 'cron.lock');
$this->assertEquals(true, file_exists($storagePath . DIRECTORY_SEPARATOR . 'cron.lock'));
Cron::setDatabaseLogging(true);
$lockfileExists = "Not called";
$report = Cron::run();
$this->assertEquals("Not called", $lockfileExists);
$this->assertEquals(-1, $report['runtime']);
$newManagerFind = \Liebig\Cron\Models\Manager::find(1);
$this->assertNotNull($newManagerFind);
$this->assertEquals(-1, $newManagerFind->runtime);
unlink($storagePath . DIRECTORY_SEPARATOR . 'cron.lock');
$this->assertEquals(false, file_exists($storagePath . DIRECTORY_SEPARATOR . 'cron.lock'));
}