Skip to content

Commit a1bdc30

Browse files
authored
feat: allow to delay ticket email (#223)
Added delay for ticket email ( attendee ) if its a single order and ticket is assigned to someone else. this is configurable by new ENV var REGISTRATION_ATTENDEE_INVITATION_EMAIL_DELAY ( minutes ) default 10 minutes. Change-Id: I66873834394743ff12b1c57cf02366a8a6af5b43
1 parent c9a49e9 commit a1bdc30

5 files changed

Lines changed: 131 additions & 2 deletions

File tree

.env.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,6 @@ AWS_ENDPOINT=
185185
REGISTRATION_ORDER_PUBLIC_EDIT_TTL=10
186186
DEFAULT_PROFILE_IMAGE=
187187
SCHEDULE_USE_REALTIME_UPDATE=1
188-
SAMSUNG_REGISTRATION_API_ENDPOINT=
188+
SAMSUNG_REGISTRATION_API_ENDPOINT=
189+
# in minutes
190+
REGISTRATION_ATTENDEE_INVITATION_EMAIL_DELAY=10
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php namespace App\Jobs;
2+
/*
3+
* Copyright 2023 OpenStack Foundation
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
**/
14+
15+
use Illuminate\Bus\Queueable;
16+
use Illuminate\Contracts\Queue\ShouldQueue;
17+
use Illuminate\Foundation\Bus\Dispatchable;
18+
use Illuminate\Queue\InteractsWithQueue;
19+
use Illuminate\Queue\SerializesModels;
20+
use Illuminate\Support\Facades\Log;
21+
use models\exceptions\EntityNotFoundException;
22+
use models\summit\ISummitAttendeeTicketRepository;
23+
use models\summit\SummitAttendeeTicket;
24+
25+
/**
26+
* Class SendAttendeeInvitationEmail
27+
* @package App\Jobs
28+
*/
29+
final class SendAttendeeInvitationEmail implements ShouldQueue
30+
{
31+
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
32+
33+
public $tries = 3;
34+
35+
public $ticket_id;
36+
37+
38+
/**
39+
* @param int $ticket_id
40+
*/
41+
public function __construct(int $ticket_id)
42+
{
43+
Log::debug(sprintf("SendAttendeeInvitationEmail::constructor ticket_id %s", $ticket_id));
44+
$this->ticket_id = $ticket_id;
45+
}
46+
47+
public function handle
48+
(
49+
ISummitAttendeeTicketRepository $ticketRepository
50+
)
51+
{
52+
Log::debug(sprintf( "SendAttendeeInvitationEmail::handle ticket_id %s", $this->ticket_id));
53+
54+
try {
55+
$ticket = $ticketRepository->getById($this->ticket_id);
56+
57+
if (!$ticket instanceof SummitAttendeeTicket) {
58+
59+
throw new EntityNotFoundException(sprintf("Ticket %s not found.", $this->ticket_id));
60+
}
61+
62+
if (!$ticket->hasOwner()) {
63+
64+
Log::warning
65+
(
66+
sprintf
67+
(
68+
"SendAttendeeInvitationEmail::handle ticket %s has no owner",
69+
$this->ticket_id
70+
)
71+
);
72+
73+
return;
74+
}
75+
76+
$attendee = $ticket->getOwner();
77+
78+
$attendee->sendInvitationEmail($ticket);
79+
}
80+
catch (\Exception $ex){
81+
Log::error($ex);
82+
throw $ex;
83+
}
84+
}
85+
86+
public function failed(\Throwable $exception)
87+
{
88+
Log::error($exception);
89+
}
90+
91+
}

app/Models/Foundation/Summit/Registration/SummitOrder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,10 @@ public function getTickets()
753753
return $this->tickets;
754754
}
755755

756+
public function isSingleTicket():bool{
757+
return $this->tickets->count() === 1;
758+
}
759+
756760
/**
757761
* @param SummitAttendeeTicket $ticket
758762
*/

app/Services/Model/Imp/SummitOrderService.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use App\Jobs\Emails\UnregisteredMemberOrderPaidMail;
2424
use App\Jobs\IngestSummitExternalRegistrationData;
2525
use App\Jobs\ProcessTicketDataImport;
26+
use App\Jobs\SendAttendeeInvitationEmail;
2627
use App\Models\Foundation\Summit\Factories\SummitOrderFactory;
2728
use App\Models\Foundation\Summit\Registration\IBuildDefaultPaymentGatewayProfileStrategy;
2829
use App\Models\Foundation\Summit\Repositories\ISummitAttendeeBadgePrintRuleRepository;
@@ -35,6 +36,7 @@
3536
use App\Services\Utils\CSVReader;
3637
use App\Services\Utils\ILockManagerService;
3738
use Illuminate\Http\UploadedFile;
39+
use Illuminate\Support\Facades\Config;
3840
use Illuminate\Support\Facades\Event;
3941
use Illuminate\Support\Facades\File;
4042
use Illuminate\Support\Facades\Log;
@@ -4068,9 +4070,37 @@ private function sendAttendeesInvitationEmail(SummitOrder $order): void
40684070
Log::debug(sprintf("SummitOrderService::sendAttendeesInvitationEmail ticket %s has not owner set", $ticket->getNumber()));
40694071
continue;
40704072
}
4073+
$attendee = $ticket->getOwner();
40714074
$ticket->generateQRCode();
40724075
$ticket->generateHash();
4073-
$ticket->getOwner()->sendInvitationEmail($ticket);
4076+
$delay = 0;
4077+
if($order->isSingleTicket() && $attendee->getEmail() !== $order->getOwnerEmail()){
4078+
Log::debug
4079+
(
4080+
sprintf
4081+
(
4082+
"SummitOrderService::sendAttendeesInvitationEmail ticket %s attendee %s is not the same as order owner %s (SOMEONE_ELSE_FLOW)",
4083+
$ticket->getId(),
4084+
$attendee->getEmail(),
4085+
$order->getOwnerEmail()
4086+
)
4087+
);
4088+
// delay invitation by N Minutes ....
4089+
$delay = Config::get("registration.attendee_invitation_email_delay", 10);
4090+
}
4091+
Log::debug
4092+
(
4093+
sprintf
4094+
(
4095+
"SummitOrderService::sendAttendeesInvitationEmail ticket %s sending invitation email to attendee %s with delay %s minutes",
4096+
$ticket->getNumber(),
4097+
$attendee->getEmail(),
4098+
$delay
4099+
)
4100+
);
4101+
4102+
SendAttendeeInvitationEmail::dispatch($ticket->getId())->delay(now()->addMinutes($delay));
4103+
40744104
} catch (\Exception $ex) {
40754105
Log::warning($ex);
40764106
}

config/registration.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@
4242
'send_ticket_attachments' => env('REGISTRATION_SEND_TICKET_ATTACHMENTS', false),
4343
'admin_ticket_edit_url' => env('REGISTRATION_ADMIN_TICKET_EDIT_URL', null),
4444
'order_public_edit_ttl' => env('REGISTRATION_ORDER_PUBLIC_EDIT_TTL', 10),
45+
// in minutes
46+
'attendee_invitation_email_delay' => env('REGISTRATION_ATTENDEE_INVITATION_EMAIL_DELAY', 10),
4547
];

0 commit comments

Comments
 (0)