Skip to content

Commit 3968d7c

Browse files
committed
Make GC on exit configurable
1 parent 17f311a commit 3968d7c

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Enable the plugin within your src/Application.php bootstrap function:
2626
$this->addPlugin('Queue');
2727
```
2828

29-
It is also advised to have the `posix` PHP extension enabled.
29+
It is also advised to have the `posix` PHP extension enabled.
3030

3131

3232
## Configuration
@@ -79,6 +79,12 @@ You may create a file called `app_queue.php` inside your `config` folder (NOT th
7979
$config['Queue']['cleanupTimeout'] = 2592000; // 30 days
8080
```
8181

82+
- Whether or not to cleanup on exit:
83+
84+
```php
85+
$config['Queue']['gcOnExit'] = true;
86+
```
87+
8288
Don't forget to load that config file with `Configure::load('app_queue');` in your bootstrap.
8389
You can also use `Plugin::load('Queue', ['bootstrap' => true]);` which will load your `app_queue.php` config file automatically.
8490

@@ -106,7 +112,7 @@ You can set two main things on each task as property: timeout and retries.
106112
* @var int
107113
*/
108114
public $timeout = 120;
109-
115+
110116
/**
111117
* Number of times a failed instance of this task should be restarted before giving up.
112118
*

src/Queue/Config.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,13 @@ public static function defaultWorkerRetries(): int
5959
{
6060
return Configure::read('Queue.defaultWorkerRetries', 4);
6161
}
62+
63+
/**
64+
*
65+
* @return int
66+
*/
67+
public static function gcOnExit(): bool
68+
{
69+
return Configure::read('Queue.gcOnExit', true);
70+
}
6271
}

src/Shell/QueueShell.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public function runworker(): void
206206
$this->_exit = true;
207207
$this->out(__d('queue', 'Reached runtime of ' . (time() - $startTime) . ' Seconds (Max ' . Configure::readOrFail('Queue.workerMaxRuntime') . '), terminating.'));
208208
}
209-
if (mt_rand(0, 100) > (100 - Config::gcprob())) {
209+
if (($this->_exit && Config::gcOnExit()) || mt_rand(0, 100) > (100 - Config::gcprob())) {
210210
$this->out(__d('queue', 'Performing old job cleanup.'));
211211
$this->QueuedTasks->cleanOldJobs($this->_getTaskConf());
212212
}

0 commit comments

Comments
 (0)