Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - SAW-1922: Add support to retry queue jobs on fail #157

Open
wants to merge 6 commits into
base: 0.7
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ RABBITMQ_DEFAULT_VHOST=/
# PAYTMENTS
STRIPE_SECRET=
STRIPE_PUBLIC=

# Delay before retrying to process a failed job
QUEUE_RETRY_DELAY=0
41 changes: 41 additions & 0 deletions src/Contracts/Metadata/MetadataTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace Baka\Contracts\Metadata;

trait MetadataTrait
{
/**
* Key/Value pairs for the metadata.
*
* @var array
*/
protected array $metadata = [];

/**
* Get metadata from the current object by it's key.
*
* @param string $key
* @param mixed $default
*
* @return mixed
*/
public function getMetadata(string $key, $default = null)
{
return $this->metadata[$key] ?? $default;
}

/**
* Set metadata for the current object.
*
* @param string $key
* @param mixed $value
*
* @return void
*/
public function setMetadata(string $key, $value) : void
{
$this->metadata[$key] = $value;
}
}
14 changes: 14 additions & 0 deletions src/Contracts/Queue/QueueableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ trait QueueableTrait
*/
public string $queue = Queue::JOBS;

/**
* whether to retry the job on fail or not.
*
* @var bool
*/
public bool $useRetry = false;

/**
* Max quantity of retries for each job.
*
* @var bool
*/
public int $maxRetryQuantity = 0;

/**
* Set the desired queue for the job.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Jobs/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

namespace Baka\Jobs;

use Baka\Contracts\Metadata\MetadataTrait;
use Baka\Contracts\Queue\QueueableJobInterface;
use Baka\Contracts\Queue\QueueableTrait;

abstract class Job implements QueueableJobInterface
{
use QueueableTrait;
use MetadataTrait;

/**
* Execute de Jobs.
Expand Down
Loading