Skip to content

Commit

Permalink
Make GC on exit configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
tersmitten committed Aug 17, 2020
1 parent 17f311a commit 3968d7c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Enable the plugin within your src/Application.php bootstrap function:
$this->addPlugin('Queue');
```

It is also advised to have the `posix` PHP extension enabled.
It is also advised to have the `posix` PHP extension enabled.


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

- Whether or not to cleanup on exit:

```php
$config['Queue']['gcOnExit'] = true;
```

Don't forget to load that config file with `Configure::load('app_queue');` in your bootstrap.
You can also use `Plugin::load('Queue', ['bootstrap' => true]);` which will load your `app_queue.php` config file automatically.

Expand Down Expand Up @@ -106,7 +112,7 @@ You can set two main things on each task as property: timeout and retries.
* @var int
*/
public $timeout = 120;

/**
* Number of times a failed instance of this task should be restarted before giving up.
*
Expand Down
9 changes: 9 additions & 0 deletions src/Queue/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,13 @@ public static function defaultWorkerRetries(): int
{
return Configure::read('Queue.defaultWorkerRetries', 4);
}

/**
*
* @return int
*/
public static function gcOnExit(): bool
{
return Configure::read('Queue.gcOnExit', true);
}
}
2 changes: 1 addition & 1 deletion src/Shell/QueueShell.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function runworker(): void
$this->_exit = true;
$this->out(__d('queue', 'Reached runtime of ' . (time() - $startTime) . ' Seconds (Max ' . Configure::readOrFail('Queue.workerMaxRuntime') . '), terminating.'));
}
if (mt_rand(0, 100) > (100 - Config::gcprob())) {
if (($this->_exit && Config::gcOnExit()) || mt_rand(0, 100) > (100 - Config::gcprob())) {
$this->out(__d('queue', 'Performing old job cleanup.'));
$this->QueuedTasks->cleanOldJobs($this->_getTaskConf());
}
Expand Down

0 comments on commit 3968d7c

Please sign in to comment.