Update ProcessMovePipeline

This commit is contained in:
Daniel Supernault 2024-09-07 01:08:39 -06:00
parent d4cf918120
commit da1de80319
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1

View file

@ -3,8 +3,10 @@
namespace App\Jobs\MovePipeline; namespace App\Jobs\MovePipeline;
use App\Services\ActivityPubFetchService; use App\Services\ActivityPubFetchService;
use Exception;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable; use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Queue\Middleware\ThrottlesExceptions;
use Illuminate\Queue\Middleware\WithoutOverlapping; use Illuminate\Queue\Middleware\WithoutOverlapping;
class ProcessMovePipeline implements ShouldQueue class ProcessMovePipeline implements ShouldQueue
@ -15,6 +17,20 @@ class ProcessMovePipeline implements ShouldQueue
public $activity; public $activity;
/**
* The number of times the job may be attempted.
*
* @var int
*/
public $tries = 6;
/**
* The maximum number of unhandled exceptions to allow before failing.
*
* @var int
*/
public $maxExceptions = 3;
/** /**
* Create a new job instance. * Create a new job instance.
*/ */
@ -31,7 +47,18 @@ class ProcessMovePipeline implements ShouldQueue
*/ */
public function middleware(): array public function middleware(): array
{ {
return [new WithoutOverlapping($this->target)]; return [
new WithoutOverlapping('process-move:'.$this->target),
(new ThrottlesExceptions(2, 5 * 60))->backoff(5),
];
}
/**
* Determine the time at which the job should timeout.
*/
public function retryUntil(): DateTime
{
return now()->addMinutes(15);
} }
/** /**
@ -39,13 +66,18 @@ class ProcessMovePipeline implements ShouldQueue
*/ */
public function handle(): void public function handle(): void
{ {
if (config('app.env') !== 'production' || (bool) config_cache('federation.activitypub.enabled') == false) {
throw new Exception('Activitypub not enabled');
}
if (! self::checkTarget()) { if (! self::checkTarget()) {
return; throw new Exception('Invalid target');
} }
if (! self::checkActor()) { if (! self::checkActor()) {
return; throw new Exception('Invalid actor');
} }
} }
protected function checkTarget() protected function checkTarget()