<commit_before># CakePHP Queue Plugin Documentation


## Installation
```
composer require dereuromark/cakephp-queue
```

Enable the plugin within your config/bootstrap.php (unless you use loadAll):
```php
Plugin::load('Queue');
```
If you want to also access the backend controller (not just using CLI), you need to use
```php
Plugin::load('Queue', ['routes' => true]);
```

Run the following command in the CakePHP console to create the tables using the Migrations plugin:
```php
bin/cake Migrations migrate -p Queue
```

## Configuration:

The plugin allows some simple runtime configuration.
You may create a file called `app_queue.php` inside your `config` folder (NOT the plugins config folder) to set the following values:

- Seconds to sleep() when no executable job is found:

		$config['Queue']['sleeptime'] = 10;

- Probability in percent of an old job cleanup happening:

		$config['Queue']['gcprob'] = 10;

- Default timeout after which a job is requeued if the worker doesn't report back:

		$config['Queue']['defaultworkertimeout'] = 3600;

- Default number of retries if a job fails or times out:

		$config['Queue']['defaultworkerretries'] = 3;

- Seconds of running time after which the worker will terminate (0 = unlimited):

		$config['Queue']['workermaxruntime'] = 60;

	Warning: Do not use 0 if you are using a cronjob to permanantly start a new worker once in a while and if you do not exit on idle.

- Should a Workerprocess quit when there are no more tasks for it to execute (true = exit, false = keep running):

		$config['Queue']['exitwhennothingtodo'] = false;

- Minimum number of seconds before a cleanup run will remove a completed task; defaults to 0 for the Queue worker, or 2592000 for the Cron worker:

		$config['Queue']['cleanuptimeout'] = 2592000; // 30 days

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.

Example `app_queue.php`:

```php
return [
	'Queue' => [
		'workermaxruntime' => 60,
		'sleeptime' => 15,
	],
];
```

You can also drop the configuration into an existing config file (recommended) that is already been loaded.
The values above are the default settings which apply, when no configuration is found.

Finally, make sure you allow the configured `pidfilepath` to be creatable and writable.
Especially on deployment some `mkdir` command might be necessary.
Set it to false to use the DB here instead, as well.

## Usage:

Run the following using the CakePHP shell:

* Display Help message:

		bin/cake queue<commit_msg>unify header style<commit_after># CakePHP Queue Plugin Documentation


## Installation
```
composer require dereuromark/cakephp-queue
```

Enable the plugin within your config/bootstrap.php (unless you use loadAll):
```php
Plugin::load('Queue');
```
If you want to also access the backend controller (not just using CLI), you need to use
```php
Plugin::load('Queue', ['routes' => true]);
```

Run the following command in the CakePHP console to create the tables using the Migrations plugin:
```php
bin/cake Migrations migrate -p Queue
```

## Configuration

The plugin allows some simple runtime configuration.
You may create a file called `app_queue.php` inside your `config` folder (NOT the plugins config folder) to set the following values:

- Seconds to sleep() when no executable job is found:

		$config['Queue']['sleeptime'] = 10;

- Probability in percent of an old job cleanup happening:

		$config['Queue']['gcprob'] = 10;

- Default timeout after which a job is requeued if the worker doesn't report back:

		$config['Queue']['defaultworkertimeout'] = 3600;

- Default number of retries if a job fails or times out:

		$config['Queue']['defaultworkerretries'] = 3;

- Seconds of running time after which the worker will terminate (0 = unlimited):

		$config['Queue']['workermaxruntime'] = 60;

	Warning: Do not use 0 if you are using a cronjob to permanantly start a new worker once in a while and if you do not exit on idle.

- Should a Workerprocess quit when there are no more tasks for it to execute (true = exit, false = keep running):

		$config['Queue']['exitwhennothingtodo'] = false;

- Minimum number of seconds before a cleanup run will remove a completed task; defaults to 0 for the Queue worker, or 2592000 for the Cron worker:

		$config['Queue']['cleanuptimeout'] = 2592000; // 30 days

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.

Example `app_queue.php`:

```php
return [
	'Queue' => [
		'workermaxruntime' => 60,
		'sleeptime' => 15,
	],
];
```

You can also drop the configuration into an existing config file (recommended) that is already been loaded.
The values above are the default settings which apply, when no configuration is found.

Finally, make sure you allow the configured `pidfilepath` to be creatable and writable.
Especially on deployment some `mkdir` command might be necessary.
Set it to false to use the DB here instead, as well.

## Usage

Run the following using the CakePHP shell:

* Display Help message:

		bin/cake queue
{'fraction_non_alphanumeric': 0.09986809873751648, 'fraction_numerical': 0.012813265498398342, 'mean_word_length': 4.640807651434644, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '176083', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1447, 'n_words': 705}