Skip to content

Commit cec30dc

Browse files
committed
Initial Delay setting
Resolves #53
1 parent 88e9f9f commit cec30dc

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Added
66
- Added new “Element is being saved for the first time” and “Element is a provisional draft” webhook filters.
77
- Some webhook filters now disable other mutually-exclusive filters when active and enabled.
8+
- Added the “Initial Delay” setting. ([#53](https://github.com/craftcms/webhooks/discussions/53))
89
- Added `craft\webhooks\filters\ExclusiveFilterInterface`.
910

1011
### Changed

src/Plugin.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,9 @@ public function request(string $method, string $url, array $headers = null, stri
323323
*/
324324
public function pushPendingJobs()
325325
{
326+
$settings = $this->getSettings();
326327
while ($job = array_shift($this->_pendingJobs)) {
327-
Queue::push($job);
328+
Queue::push($job, null, $settings->initialDelay);
328329
}
329330
}
330331

src/Settings.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ class Settings extends Model
1818
*/
1919
public $maxAttempts = 1;
2020

21+
/**
22+
* @var int|null The time delay in seconds that initial webhook request attempts should have.
23+
* @since 2.4.0
24+
*/
25+
public $initialDelay;
26+
2127
/**
2228
* @var int The time delay in seconds between request retries.
2329
* @since 2.3.0
@@ -40,6 +46,10 @@ public function setAttributes($values, $safeOnly = true)
4046
$values['retryDelay'] = $retryDelay;
4147
}
4248

49+
if (empty($values['initialDelay'])) {
50+
$values['initialDelay'] = null;
51+
}
52+
4353
parent::setAttributes($values, $safeOnly);
4454
}
4555

@@ -50,7 +60,7 @@ protected function defineRules(): array
5060
{
5161
return [
5262
[['maxDepth', 'maxAttempts'], 'number', 'integerOnly' => true, 'min' => 1],
53-
[['retryDelay'], 'number', 'integerOnly' => true, 'min' => 0],
63+
[['initialDelay', 'retryDelay'], 'number', 'integerOnly' => true, 'min' => 0],
5464
];
5565
}
5666

src/templates/_settings.twig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
value: settings.maxAttempts,
2020
}) }}
2121

22+
{{ forms.textField({
23+
id: 'initial-delay',
24+
label: 'Initial Delay'|t('webhooks'),
25+
instructions: 'The time delay in seconds that initial webhook requests should have.'|t('webhooks'),
26+
size: 5,
27+
name: 'initialDelay',
28+
value: settings.initialDelay,
29+
}) }}
30+
2231
{{ forms.textField({
2332
id: 'retry-delay',
2433
label: 'Retry Delay'|t('webhooks'),

0 commit comments

Comments
 (0)