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.
132 righe
3.5 KiB
132 righe
3.5 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; |
|
|
|
class CheckPreservationStatusJob 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; |
|
|
|
/** |
|
* Indicate if the job should be marked as failed on timeout. |
|
* |
|
* @var bool |
|
*/ |
|
public $failOnTimeout = true; |
|
|
|
/** |
|
* 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 * 1 . "M"); |
|
|
|
$preservation = new PreservationClass($this->tenant, $this->package); |
|
$preservation->checkPreservationStatus(); |
|
|
|
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'); |
|
|
|
$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 = "Impossibile recupero lo stato del pacchetto di conservazione #{$this->package} dell'ente #{$this->tenant} (CheckPreservationStatusJob.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"]); |
|
} |
|
|
|
}); |
|
} |
|
}
|
|
|