mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-25 15:55:22 +00:00
Update FetchNodeinfoPipeline, use more efficient dispatch
This commit is contained in:
parent
289cad470b
commit
ac01f51ab6
1 changed files with 62 additions and 35 deletions
|
@ -4,6 +4,7 @@ namespace App\Jobs\InstancePipeline;
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
@ -12,8 +13,10 @@ use Illuminate\Support\Facades\Http;
|
||||||
use App\Instance;
|
use App\Instance;
|
||||||
use App\Profile;
|
use App\Profile;
|
||||||
use App\Services\NodeinfoService;
|
use App\Services\NodeinfoService;
|
||||||
|
use Illuminate\Contracts\Cache\Repository;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
class FetchNodeinfoPipeline implements ShouldQueue
|
class FetchNodeinfoPipeline implements ShouldQueue, ShouldBeUniqueUntilProcessing
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
@ -29,6 +32,21 @@ class FetchNodeinfoPipeline implements ShouldQueue
|
||||||
$this->instance = $instance;
|
$this->instance = $instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of seconds after which the job's unique lock will be released.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $uniqueFor = 14400;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the unique ID for the job.
|
||||||
|
*/
|
||||||
|
public function uniqueId(): string
|
||||||
|
{
|
||||||
|
return $this->instance->id;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the job.
|
* Execute the job.
|
||||||
*
|
*
|
||||||
|
@ -38,18 +56,27 @@ class FetchNodeinfoPipeline implements ShouldQueue
|
||||||
{
|
{
|
||||||
$instance = $this->instance;
|
$instance = $this->instance;
|
||||||
|
|
||||||
|
if( $instance->nodeinfo_last_fetched &&
|
||||||
|
$instance->nodeinfo_last_fetched->gt(now()->subHours(12)) ||
|
||||||
|
$instance->delivery_timeout &&
|
||||||
|
$instance->delivery_next_after->gt(now())
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$ni = NodeinfoService::get($instance->domain);
|
$ni = NodeinfoService::get($instance->domain);
|
||||||
|
$instance->last_crawled_at = now();
|
||||||
if($ni) {
|
if($ni) {
|
||||||
if(isset($ni['software']) && is_array($ni['software']) && isset($ni['software']['name'])) {
|
if(isset($ni['software']) && is_array($ni['software']) && isset($ni['software']['name'])) {
|
||||||
$software = $ni['software']['name'];
|
$software = $ni['software']['name'];
|
||||||
$instance->software = strtolower(strip_tags($software));
|
$instance->software = strtolower(strip_tags($software));
|
||||||
$instance->last_crawled_at = now();
|
|
||||||
$instance->user_count = Profile::whereDomain($instance->domain)->count();
|
$instance->user_count = Profile::whereDomain($instance->domain)->count();
|
||||||
|
$instance->nodeinfo_last_fetched = now();
|
||||||
$instance->save();
|
$instance->save();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$instance->user_count = Profile::whereDomain($instance->domain)->count();
|
$instance->delivery_timeout = 1;
|
||||||
$instance->last_crawled_at = now();
|
$instance->delivery_next_after = now()->addHours(14);
|
||||||
$instance->save();
|
$instance->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue