1+ <?php namespace App \Jobs ;
2+ /*
3+ * Copyright 2025 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+ use App \Events \SponsorServices \SponsorDomainEvents ;
15+ use App \Models \Foundation \Summit \Repositories \ISponsorRepository ;
16+ use App \Services \Model \Imp \Factories \RabbitPublisherFactory ;
17+ use Illuminate \Bus \Queueable ;
18+ use Illuminate \Contracts \Queue \ShouldQueue ;
19+ use Illuminate \Foundation \Bus \Dispatchable ;
20+ use Illuminate \Queue \InteractsWithQueue ;
21+ use Illuminate \Queue \SerializesModels ;
22+ use Illuminate \Support \Facades \Log ;
23+
24+ class CompanyEventJob implements ShouldQueue
25+ {
26+ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
27+
28+ public $ tries = 5 ;
29+
30+ private $ op ;
31+
32+ private $ company_id ;
33+
34+ /**
35+ * @param int $company_id
36+ * @param string $op
37+ */
38+ public function __construct (int $ company_id , string $ op ){
39+ $ this ->op = $ op ;
40+ $ this ->company_id = $ company_id ;
41+ Log::debug (sprintf ("CompanyEventJob::construct op %s company_id %s " , $ op , $ this ->company_id ));
42+ }
43+
44+ /**
45+ * @param ISponsorRepository $sponsor_repository
46+ * @return void
47+ */
48+ public function handle (ISponsorRepository $ sponsor_repository ){
49+ Log::debug (sprintf ("CompanyEventJob::handle op %s company_id %s " , $ this ->op , $ this ->company_id ));
50+ $ excerpt = $ sponsor_repository ->getSponsorsExcerptByCompanyID ($ this ->company_id );
51+ $ domain_event_publisher_service = RabbitPublisherFactory::make ('domain_events_message_broker ' );
52+ Log::debug (sprintf ("CompanyEventJob::handle excerpt %s " , json_encode ($ excerpt )));
53+ foreach ($ excerpt as $ entry ) {
54+ $ payload = [
55+ 'id ' => intval ($ entry ['sponsor_id ' ])
56+ ];
57+ $ routing_key = $ this ->op == 'UPDATE ' ? SponsorDomainEvents::SponsorUpdated : SponsorDomainEvents::SponsorDeleted;
58+ $ domain_event_publisher_service ->publish ($ payload , $ routing_key );
59+ }
60+ }
61+
62+
63+ public function failed (\Throwable $ e ): void
64+ {
65+ Log::error ("CompanyEventJob::failed {$ e ->getMessage ()}" );
66+ }
67+
68+ }
0 commit comments