mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Fix impossible function cron schedules
This commit is contained in:
3 files changed
+12
-2
No files matched your search
@@ -56,12 +56,15 @@ class ScheduleFunctions extends ScheduleBase
|
||||
foreach ($this->schedules as $key => $schedule) {
|
||||
try {
|
||||
$cron = new CronExpression($schedule['schedule']);
|
||||
$nextDate = $cron->getNextRunDate();
|
||||
} catch (\InvalidArgumentException) {
|
||||
// ignore invalid cron expressions
|
||||
continue;
|
||||
} catch (\RuntimeException) {
|
||||
// ignore impossible cron expressions
|
||||
continue;
|
||||
}
|
||||
|
||||
$nextDate = $cron->getNextRunDate();
|
||||
$next = DateTime::format($nextDate);
|
||||
|
||||
$currentTick = $next < $timeFrame;
|
||||
|
||||
@@ -38,7 +38,12 @@ class Cron extends Validator
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
try {
|
||||
(new CronExpression($value))->getNextRunDate();
|
||||
return true;
|
||||
} catch (\RuntimeException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,12 +28,14 @@ class CronTest extends TestCase
|
||||
$this->assertEquals($this->object->isValid('* * * * *'), true); // execute on every minutes
|
||||
// $this->assertEquals($this->object->isValid('0 17 * * sun'), true); // execute on every Sunday at 5 PM
|
||||
$this->assertEquals($this->object->isValid('*/10 * * * *'), true); // execute on every 10 minutes
|
||||
$this->assertEquals($this->object->isValid('*/5 22-23,0-3 * * *'), true); // execute every 5 minutes from 10pm to 3am
|
||||
// $this->assertEquals($this->object->isValid('* * * jan,may,aug *'), true); // execute on selected months
|
||||
// $this->assertEquals($this->object->isValid('0 17 * * sun,fri'), true); // execute on selected days
|
||||
// $this->assertEquals($this->object->isValid('0 2 * * sun'), true); // execute on first sunday of every month
|
||||
$this->assertEquals($this->object->isValid('0 */4 * * *'), true); // execute on every four hours
|
||||
// $this->assertEquals($this->object->isValid('0 4,17 * * sun,mon'), true); // execute twice on every Sunday and Monday
|
||||
$this->assertEquals($this->object->isValid('bad expression'), false);
|
||||
$this->assertEquals($this->object->isValid('*/5 22-3 * * *'), false);
|
||||
$this->assertEquals(null, false);
|
||||
$this->assertEquals('', false);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user