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.
 
 
 
 
 

133 righe
3.6 KiB

<?php
namespace App\Jobs\Preservation;
use Throwable;
use Illuminate\Bus\Queueable;
use App\Classes\PreservationClass;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use App\Models\Tenant\Conservazione\File as Item;
use App\Models\Tenant\Conservazione\Conservazione;
use App\Models\Tenant\Conservazione\Conservazione as Package;
class SendPackageJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* The number of times the job may be attempted.
*
* @var int
*/
public $tries = 5;
/**
* The maximum number of unhandled exceptions to allow before failing.
*
* @var int
*/
public $maxExceptions = 5;
/**
* The number of seconds the job can run before timing out.
*
* @var int
*/
public $timeout = 1800;
/**
* Tenant's id
*
* @var Int
*/
protected $tenant;
/**
* Package's id
*
* @var Int
*/
protected $package;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(Int $tenant, Int $package)
{
$this->tenant = $tenant;
$this->package = $package;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$limit = ini_get('memory_limit');
ini_set('memory_limit', 1024 * 5 . "M");
$preservation = new PreservationClass($this->tenant, $this->package);
$preservation->pushCollection();
ini_set('memory_limit', $limit);
}
/**
* Handle a job failure.
*
* @param \Throwable $exception
* @return void
*/
public function failed(Throwable $exception)
{
Log::emergency($exception);
return;
$prefix = config('json.prefix_db');
config(['database.connections.mysql-tenant.database' => "{$prefix}_ente{$this->tenant}"]);
DB::purge('mysql-tenant');
$package = Package::findOrFail($this->package);
$package->stato = 90;
$package->save();
$config = config("json", null);
$alerts = $config["alerts"];
config([
"mail.mailers.smtp.host" => $alerts["config"]["smtp"],
"mail.mailers.smtp.port" => $alerts["config"]["port"],
"mail.mailers.smtp.encryption" => "ssl",
"mail.mailers.smtp.username" => $alerts["config"]["username"],
"mail.mailers.smtp.password" => $alerts["config"]["password"],
]);
$message = "Errore durante il recupero dei file del pacchetto di conservazione #{$this->package} dell'ente #{$this->tenant} (SendPackageJob.php)" . PHP_EOL;
$message .= $exception->getMessage();
Mail::raw($message, function ($message) use ($alerts, $config) {
$message->priority(3);
$message->subject("{$config["nome_sito"]}: verifica modulo conservazione sostitutiva.");
if(! empty($alerts["from"]["email"])) { $message->from($alerts["from"]["email"], $alerts["from"]["name"]); }
if(! empty($alerts["reply"]["email"])) { $message->replyTo($alerts["reply"]["email"], $alerts["reply"]["name"]); }
foreach ($alerts["to"] as $address) {
$message->to($address["email"], $address["name"]);
}
});
}
}