gestione gare pubbliche
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

122 righe
3.4 KiB

<?php
namespace App\Console\Commands\Preservation;
use App\Models\Main\Tenant;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use App\Jobs\Preservation\GetFilesJob;
use App\Jobs\Preservation\SendPackageJob;
use App\Models\Tenant\Conservazione\Conservazione;
use App\Jobs\Preservation\CheckPreservationStatusJob;
class TenantTaskSchedulerCommand extends Command
{
/**
* Tenant id
*
* @var Int
*/
private $tenant;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'preservation:job-schedule
{--T|tenant= : Tenant Identifier}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'The command manages the scheduling and administration of preservation jobs for a specific tenant.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$this->tenant = $this->option("tenant");
setup_db_connection();
if(config('database.connections.mysql-tenant.database') != config('json.prefix_db') . "_ente{$this->tenant}") {
config(['database.connections.mysql-tenant.database' => config('json.prefix_db') . "_ente{$this->tenant}"]);
DB::purge('mysql-tenant');
}
$collections = Conservazione::where("stato", "<=", 20)->limit(200)->get();
foreach($collections as $collection) {
if($collection->tipologia == "conservazione") {
if ($collection->items()->count() < 1) {
$this->info("Scheduling retrieval of files for package #{$collection->codice}");
GetFilesJob::dispatchSync($this->tenant, $collection->codice);
}
if($collection->items()->where('stato', '<>', '20')->count() < 1) {
$this->info("Checking the status of package #{$collection->codice}");
CheckPreservationStatusJob::dispatchSync($this->tenant, $collection->codice);
} else {
$this->info("Scheduling the sending of package #{$collection->codice}");
SendPackageJob::dispatch($this->tenant, $collection->codice)
->onConnection("database")
->onQueue("preservation")
->delay(0);
}
}
}
$collections = Conservazione::where("stato", "=", 90)->limit(100)->get();
if(! empty($collections)) {
foreach($collections as $collection) {
$collection->items()->update(['stato' => 0, 'uID' => null, 'hash' => null]);
$collection->pid = null;
$collection->stato = 5;
$collection->save();
$this->info("Scheduling the sending of package #{$collection->codice}, which previously failed");
SendPackageJob::dispatch($this->tenant, $collection->codice)
->onConnection("database")
->onQueue("preservation")
->delay(0);
}
}
return 0;
}
}