|
|
|
|
@ -9,14 +9,36 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
|
|
class NewStatusPipeline implements ShouldQueue
|
|
|
|
|
{
|
|
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Seconds between checks while attached media is still being processed.
|
|
|
|
|
*/
|
|
|
|
|
public const MEDIA_WAIT_SECONDS = 10;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* How many checks to make before giving up (30 x 10s = 5 minutes).
|
|
|
|
|
*/
|
|
|
|
|
public const MEDIA_WAIT_MAX = 30;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Seconds to hold the publish lock. Long enough to cover the waiting
|
|
|
|
|
* job and the media pipeline both dispatching for the same status.
|
|
|
|
|
*/
|
|
|
|
|
private const LOCK_TTL = 900;
|
|
|
|
|
|
|
|
|
|
protected $status;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* How many times this status has already been re-queued waiting on media.
|
|
|
|
|
*/
|
|
|
|
|
protected int $mediaWait;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete the job if its models no longer exist.
|
|
|
|
|
*
|
|
|
|
|
@ -42,9 +64,10 @@ class NewStatusPipeline implements ShouldQueue
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(Status $status)
|
|
|
|
|
public function __construct(Status $status, int $mediaWait = 0)
|
|
|
|
|
{
|
|
|
|
|
$this->status = $status;
|
|
|
|
|
$this->mediaWait = $mediaWait;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -68,22 +91,54 @@ class NewStatusPipeline implements ShouldQueue
|
|
|
|
|
// Don't publish the status, and just no-op
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (config_cache('pixelfed.cloud_storage') && ! config('pixelfed.media_fast_process')) {
|
|
|
|
|
$still_processing = Media::whereStatusId($this->status->id)
|
|
|
|
|
$still_processing = Media::whereStatusId($status->id)
|
|
|
|
|
->whereNull('cdn_url')
|
|
|
|
|
->exists();
|
|
|
|
|
|
|
|
|
|
if ($still_processing) {
|
|
|
|
|
// The media items in the status are still being processed.
|
|
|
|
|
// We can't publish the status to ActivityPub because the final remote URL is not
|
|
|
|
|
// yet known. Instead, do nothing here. The media pipeline will re-call the NewStatusPipeline
|
|
|
|
|
// once all media items are finished processing
|
|
|
|
|
// yet known.
|
|
|
|
|
//
|
|
|
|
|
// MediaStorageService::cloudStore() re-dispatches this job when the last attachment
|
|
|
|
|
// lands on cloud storage, but that only helps if the media pipeline actually gets
|
|
|
|
|
// there. Poll as a fallback so a post is never silently left unpublished.
|
|
|
|
|
if ($this->mediaWait >= self::MEDIA_WAIT_MAX) {
|
|
|
|
|
Log::warning(
|
|
|
|
|
"NewStatusPipeline: Media for status {$status->id} never finished processing, giving up after "
|
|
|
|
|
.(self::MEDIA_WAIT_MAX * self::MEDIA_WAIT_SECONDS).'s'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self::dispatch($status, $this->mediaWait + 1)
|
|
|
|
|
->onQueue($this->queue)
|
|
|
|
|
->delay(now()->addSeconds(self::MEDIA_WAIT_SECONDS));
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Both the fallback above and MediaStorageService::cloudStore() can
|
|
|
|
|
* dispatch this job for the same status once its media is ready.
|
|
|
|
|
* Only the first one through should lex and federate it.
|
|
|
|
|
*/
|
|
|
|
|
$lock = 'pf:status:new-pipeline:'.$status->id;
|
|
|
|
|
|
|
|
|
|
if (! Cache::add($lock, 1, self::LOCK_TTL)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
StatusEntityLexer::dispatch($status);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
// Let the queue retry take the lock next time.
|
|
|
|
|
Cache::forget($lock);
|
|
|
|
|
|
|
|
|
|
Log::warning("NewStatusPipeline: Failed to dispatch StatusEntityLexer for status {$status->id}: ".$e->getMessage());
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
|