pixelfed/app/Jobs/HomeFeedPipeline/FeedInsertPipeline.php

74 lines
1.7 KiB
PHP
Raw Normal View History

2023-11-11 14:23:42 +00:00
<?php
namespace App\Jobs\HomeFeedPipeline;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing;
use App\Services\FollowerService;
use App\Services\HomeTimelineService;
class FeedInsertPipeline implements ShouldQueue, ShouldBeUniqueUntilProcessing
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
2023-11-13 03:54:32 +00:00
protected $sid;
protected $pid;
2023-11-11 14:23:42 +00:00
public $timeout = 900;
public $tries = 3;
public $maxExceptions = 1;
public $failOnTimeout = true;
/**
* The number of seconds after which the job's unique lock will be released.
*
* @var int
*/
public $uniqueFor = 3600;
/**
* Get the unique ID for the job.
*/
public function uniqueId(): string
{
2023-11-13 03:54:32 +00:00
return 'hts:feed:insert:sid:' . $this->sid;
2023-11-11 14:23:42 +00:00
}
/**
* Get the middleware the job should pass through.
*
* @return array<int, object>
*/
public function middleware(): array
{
2023-11-13 03:54:32 +00:00
return [(new WithoutOverlapping("hts:feed:insert:sid:{$this->sid}"))->shared()->dontRelease()];
2023-11-11 14:23:42 +00:00
}
/**
* Create a new job instance.
*/
2023-11-13 03:54:32 +00:00
public function __construct($sid, $pid)
2023-11-11 14:23:42 +00:00
{
2023-11-13 03:54:32 +00:00
$this->sid = $sid;
$this->pid = $pid;
2023-11-11 14:23:42 +00:00
}
/**
* Execute the job.
*/
public function handle(): void
{
2023-11-13 03:54:32 +00:00
$ids = FollowerService::localFollowerIds($this->pid);
2023-11-11 14:23:42 +00:00
foreach($ids as $id) {
2023-11-13 03:54:32 +00:00
HomeTimelineService::add($id, $this->sid);
2023-11-11 14:23:42 +00:00
}
}
}