Skip to content

Commit

Permalink
feat: allow configuration of key parameters for the queue (#5)
Browse files Browse the repository at this point in the history
* feat: allow configuration of key parameters for the queue

* Apply fixes from StyleCI

---------

Co-authored-by: StyleCI Bot <[email protected]>
  • Loading branch information
imorland and StyleCIBot committed Jan 5, 2024
1 parent 61bf2a7 commit c90fc0f
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
13 changes: 10 additions & 3 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Blomstra\DatabaseQueue;

use Blomstra\DatabaseQueue\Console\WorkerArgs;
use Flarum\Extend;
use Illuminate\Console\Scheduling\Event;

Expand All @@ -30,8 +31,14 @@

(new Extend\Console())
->command(Console\DatabaseWorkCommand::class)
->schedule('queue:work --stop-when-empty', function (Event $e) {
->schedule('queue:work', function (Event $e) {
$e->everyMinute();
}),

}, resolve(WorkerArgs::class)->args()),

(new Extend\Settings())
->default('blomstra-database-queue.retries', 1)
->default('blomstra-database-queue.timeout', 60)
->default('blomstra-database-queue.rest', 0)
->default('blomstra-database-queue.memory', 128)
->default('blomstra-database-queue.backoff', 0),
];
16 changes: 16 additions & 0 deletions resources/locale/en.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
blomstra-database-queue:
admin:
settings:
backoff_label: Backoff
backoff_help: |
The number of seconds to wait before retrying a job that encountered an uncaught exception.
memory_label: Memory
memory_help: |
The memory limit in megabytes.
rest_label: Rest
rest_help: |
The number of seconds to rest between jobs.
retries_label: Retries
retries_help: |
The number of times to attempt a job before logging it failed.
timeout_label: Timeout
timeout_help: |
The number of seconds a child process can run.
stats:
auto_refresh: Auto Refresh
heading: Queue Overview
Expand Down
43 changes: 43 additions & 0 deletions src/Console/WorkerArgs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/*
* This file is part of blomstra/database-queue
*
* Copyright (c) 2023 Blomstra Ltd.
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*
*/

namespace Blomstra\DatabaseQueue\Console;

use Flarum\Settings\SettingsRepositoryInterface;

class WorkerArgs
{
/**
* @var SettingsRepositoryInterface
*/
protected $settings;

public function __construct(SettingsRepositoryInterface $settings)
{
$this->settings = $settings;
}

public function args(): array
{
$args = [
'--stop-when-empty',
];

$args['--tries'] = $this->settings->get('blomstra-database-queue.retries');
$args['--timeout'] = $this->settings->get('blomstra-database-queue.timeout');
$args['--rest'] = $this->settings->get('blomstra-database-queue.rest');
$args['--memory'] = $this->settings->get('blomstra-database-queue.memory');
$args['--backoff'] = $this->settings->get('blomstra-database-queue.backoff');

return $args;
}
}

0 comments on commit c90fc0f

Please sign in to comment.