mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-01-29 07:19:32 -06:00
78 lines
1.8 KiB
PHP
78 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* NOTICE OF LICENSE.
|
|
*
|
|
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
|
|
* The details is bundled with this project in the file LICENSE.txt.
|
|
*
|
|
* @project UNIT3D Community Edition
|
|
*
|
|
* @author HDVinnie <hdinnovations@protonmail.com>
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
|
*/
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Http\Middleware\RateLimitOutboundMail;
|
|
use App\Models\User;
|
|
use App\Notifications\MassEmail;
|
|
use DateTime;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class SendMassEmail implements ShouldQueue
|
|
{
|
|
use Dispatchable;
|
|
use InteractsWithQueue;
|
|
use Queueable;
|
|
use SerializesModels;
|
|
|
|
/**
|
|
* The number of times the job may be attempted.
|
|
*/
|
|
public int $tries = 3;
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*/
|
|
public function __construct(public User $user, public string $subject, public string $message)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Get the middleware the job should pass through.
|
|
*
|
|
* @return array<int, object>
|
|
*/
|
|
public function middleware(): array
|
|
{
|
|
return [new RateLimitOutboundMail()];
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*/
|
|
public function handle(): void
|
|
{
|
|
if ($this->attempts() > 2) {
|
|
$this->delay(min(5 * $this->attempts(), 300));
|
|
}
|
|
|
|
$this->user->notify(new MassEmail($this->subject, $this->message));
|
|
}
|
|
|
|
/**
|
|
* Determine the time at which the job should timeout.
|
|
*/
|
|
public function retryUntil(): DateTime
|
|
{
|
|
return now()->addHours(2);
|
|
}
|
|
}
|