Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 783a4d0

Browse files
committed
Set a minimum increment for jobs
1 parent 0c4f1ea commit 783a4d0

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

_config/settings.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
Name: pseudocron
3+
---
4+
CronJob:
5+
minimum_increment: 60

code/CronJob.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function execute() {
8080
}
8181

8282
$this->LastRun = $now;
83-
$this->NextRun = $now + $this->Increment;
83+
$this->NextRun = $now + max($this->Increment, $this->config()->minimum_increment);
8484

8585
// Execute isn't in the business of creating jobs
8686
if ( $this->ID ) $this->write();
@@ -110,4 +110,16 @@ public function getCallback() {
110110
}
111111
return $val;
112112
}
113+
114+
/**
115+
* Enforce that the Increment should be either null or greater than the minimum.
116+
* @param int|null $value The value to set.
117+
* @throws InvalidArgumentException
118+
*/
119+
public function setIncrement($value) {
120+
if ( !(is_null($value) || is_int($value)) || (is_int($value) && $value < $this->config()->minimum_increment) ) {
121+
throw new InvalidArgumentException('The increment must be greater than ' . $this->config()->minimum_increment . ' seconds.');
122+
}
123+
$this->setField('Increment', $value);
124+
}
113125
}

0 commit comments

Comments
 (0)