Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions docs/basic-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ namespace App\Jobs;

use Exception;
use CodeIgniter\Queue\BaseJob;
use CodeIgniter\Queue\Interfaces\JobInterface;

class Email extends BaseJob implements JobInterface
class Email extends BaseJob
{
/**
* @throws Exception
Expand Down Expand Up @@ -94,7 +93,7 @@ If you have to use transactions in your Job - this is a simple schema you can fo
```php
// ...

class Email extends BaseJob implements JobInterface
class Email extends BaseJob
{
/**
* @throws Exception
Expand Down Expand Up @@ -130,7 +129,7 @@ We can also configure some things on the job level. It's a number of tries, when
```php
// ...

class Email extends BaseJob implements JobInterface
class Email extends BaseJob
{
protected int $retryAfter = 60;
protected int $tries = 1;
Expand Down
6 changes: 5 additions & 1 deletion src/BaseJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

namespace CodeIgniter\Queue;

abstract class BaseJob
use CodeIgniter\Queue\Interfaces\JobInterface;

abstract class BaseJob implements JobInterface
{
// Retry job after X seconds
protected int $retryAfter = 60;
Expand All @@ -25,6 +27,8 @@ public function __construct(protected array $data)
{
}

abstract public function process();

public function getRetryAfter(): int
{
return $this->retryAfter;
Expand Down
3 changes: 1 addition & 2 deletions src/Commands/Generators/Views/job.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
namespace {namespace};

use CodeIgniter\Queue\BaseJob;
use CodeIgniter\Queue\Interfaces\JobInterface;

class {class} extends BaseJob implements JobInterface
class {class} extends BaseJob
{
public function process()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Handlers/BaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use CodeIgniter\Queue\Entities\QueueJob;
use CodeIgniter\Queue\Entities\QueueJobFailed;
use CodeIgniter\Queue\Exceptions\QueueException;
use CodeIgniter\Queue\Interfaces\QueueInterface;
use CodeIgniter\Queue\Models\QueueJobFailedModel;
use CodeIgniter\Queue\Payloads\ChainBuilder;
use CodeIgniter\Queue\Payloads\PayloadMetadata;
Expand All @@ -30,7 +31,7 @@
/**
* @property QueueConfig $config
*/
abstract class BaseHandler
abstract class BaseHandler implements QueueInterface
{
use HasQueueValidation;

Expand Down
3 changes: 1 addition & 2 deletions src/Handlers/DatabaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use CodeIgniter\Queue\Entities\QueueJob;
use CodeIgniter\Queue\Enums\Status;
use CodeIgniter\Queue\Events\QueueEventManager;
use CodeIgniter\Queue\Interfaces\QueueInterface;
use CodeIgniter\Queue\Models\QueueJobModel;
use CodeIgniter\Queue\Payloads\Payload;
use CodeIgniter\Queue\Payloads\PayloadMetadata;
Expand All @@ -28,7 +27,7 @@
use RuntimeException;
use Throwable;

class DatabaseHandler extends BaseHandler implements QueueInterface
class DatabaseHandler extends BaseHandler
{
private readonly QueueJobModel $jobModel;

Expand Down
3 changes: 1 addition & 2 deletions src/Handlers/PredisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use CodeIgniter\Queue\Entities\QueueJob;
use CodeIgniter\Queue\Enums\Status;
use CodeIgniter\Queue\Events\QueueEventManager;
use CodeIgniter\Queue\Interfaces\QueueInterface;
use CodeIgniter\Queue\Payloads\Payload;
use CodeIgniter\Queue\Payloads\PayloadMetadata;
use CodeIgniter\Queue\QueuePushResult;
Expand All @@ -29,7 +28,7 @@
use RuntimeException;
use Throwable;

class PredisHandler extends BaseHandler implements QueueInterface
class PredisHandler extends BaseHandler
{
private readonly Client $predis;
private readonly string $luaScript;
Expand Down
3 changes: 1 addition & 2 deletions src/Handlers/RabbitMQHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use CodeIgniter\Queue\Enums\Status;
use CodeIgniter\Queue\Events\QueueEventManager;
use CodeIgniter\Queue\Exceptions\QueueException;
use CodeIgniter\Queue\Interfaces\QueueInterface;
use CodeIgniter\Queue\Payloads\Payload;
use CodeIgniter\Queue\Payloads\PayloadMetadata;
use CodeIgniter\Queue\QueuePushResult;
Expand All @@ -32,7 +31,7 @@
use PhpAmqpLib\Wire\AMQPTable;
use Throwable;

class RabbitMQHandler extends BaseHandler implements QueueInterface
class RabbitMQHandler extends BaseHandler
{
private readonly AbstractConnection $connection;
private readonly AMQPChannel $channel;
Expand Down
3 changes: 1 addition & 2 deletions src/Handlers/RedisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use CodeIgniter\Queue\Entities\QueueJob;
use CodeIgniter\Queue\Enums\Status;
use CodeIgniter\Queue\Events\QueueEventManager;
use CodeIgniter\Queue\Interfaces\QueueInterface;
use CodeIgniter\Queue\Payloads\Payload;
use CodeIgniter\Queue\Payloads\PayloadMetadata;
use CodeIgniter\Queue\QueuePushResult;
Expand All @@ -29,7 +28,7 @@
use RuntimeException;
use Throwable;

class RedisHandler extends BaseHandler implements QueueInterface
class RedisHandler extends BaseHandler
{
private readonly Redis $redis;
private readonly string $luaScript;
Expand Down
29 changes: 19 additions & 10 deletions src/Interfaces/QueueInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,37 @@

namespace CodeIgniter\Queue\Interfaces;

use Closure;
use CodeIgniter\Queue\Entities\QueueJob;
use CodeIgniter\Queue\Payloads\PayloadMetadata;
use CodeIgniter\Queue\QueuePushResult;
use Throwable;

interface QueueInterface
{
public function push(string $queue, string $job, array $data);
public function push(string $queue, string $job, array $data, ?PayloadMetadata $metadata = null): QueuePushResult;

public function pop(string $queue, array $priorities);
public function pop(string $queue, array $priorities): ?QueueJob;

public function later(QueueJob $queueJob, int $seconds);
public function later(QueueJob $queueJob, int $seconds): bool;

public function failed(QueueJob $queueJob, Throwable $err, bool $keepJob);
public function failed(QueueJob $queueJob, Throwable $err, bool $keepJob): bool;

public function done(QueueJob $queueJob);
public function done(QueueJob $queueJob): bool;

public function clear(?string $queue = null);
public function clear(?string $queue = null): bool;

public function retry(?int $id, ?string $queue);
public function retry(?int $id, ?string $queue): int;

public function forget(int $id);
public function forget(int $id): bool;

public function flush(?int $hours, ?string $queue);
public function flush(?int $hours, ?string $queue): bool;

public function listFailed(?string $queue);
public function listFailed(?string $queue): array;

public function setDelay(int $delay): static;

public function setPriority(string $priority): static;

public function chain(Closure $callback): QueuePushResult;
}
3 changes: 1 addition & 2 deletions tests/_support/Jobs/Failure.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
namespace Tests\Support\Jobs;

use CodeIgniter\Queue\BaseJob;
use CodeIgniter\Queue\Interfaces\JobInterface;
use Exception;

class Failure extends BaseJob implements JobInterface
class Failure extends BaseJob
{
/**
* @throws Exception
Expand Down
3 changes: 1 addition & 2 deletions tests/_support/Jobs/Success.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
namespace Tests\Support\Jobs;

use CodeIgniter\Queue\BaseJob;
use CodeIgniter\Queue\Interfaces\JobInterface;

class Success extends BaseJob implements JobInterface
class Success extends BaseJob
{
protected int $retryAfter = 6;
protected int $tries = 3;
Expand Down
Loading