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+
15+
16+ use Illuminate \Bus \Queueable ;
17+ use Illuminate \Contracts \Queue \ShouldQueue ;
18+ use Illuminate \Foundation \Bus \Dispatchable ;
19+ use Illuminate \Queue \InteractsWithQueue ;
20+ use Illuminate \Queue \SerializesModels ;
21+ use Illuminate \Support \Facades \Log ;
22+ use models \exceptions \ValidationException ;
23+ use OpenId \Services \IUserService ;
24+
25+ /**
26+ * Class NotifyMonitoredSecurityGroupActivity
27+ * @package App\Jobs
28+ */
29+ final class NotifyMonitoredSecurityGroupActivity implements ShouldQueue
30+ {
31+ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
32+
33+ const ACTION_ADD_2_GROUP = 'Added ' ;
34+ const REMOVE_FROM_GROUP = 'Removed ' ;
35+
36+ const ValidActions = [
37+ self ::ACTION_ADD_2_GROUP ,
38+ self ::REMOVE_FROM_GROUP
39+ ];
40+
41+ public $ tries = 1 ;
42+
43+ public $ timeout = 0 ;
44+
45+ /**
46+ * @var string
47+ */
48+ public $ action ;
49+
50+ /**
51+ * @var int
52+ */
53+ public $ user_id ;
54+
55+ /**
56+ * @var string
57+ */
58+ public $ user_email ;
59+
60+ /*
61+ * @var string
62+ */
63+ public $ user_name ;
64+
65+ /**
66+ * @var int
67+ */
68+ public $ group_id ;
69+
70+ /**
71+ * @var string
72+ */
73+ public $ group_name ;
74+
75+ /**
76+ * @var string
77+ */
78+ public $ group_slug ;
79+
80+ /**
81+ * @param string $action
82+ * @param int $user_id
83+ * @param string $user_email
84+ * @param string $user_name
85+ * @param int $group_id
86+ * @param string $group_name
87+ * @param string $group_slug
88+ * @throws ValidationException
89+ */
90+ public function __construct
91+ (
92+ string $ action ,
93+ int $ user_id ,
94+ string $ user_email ,
95+ string $ user_name ,
96+ int $ group_id ,
97+ string $ group_name ,
98+ string $ group_slug
99+ )
100+ {
101+ if (!in_array ($ action , self ::ValidActions)){
102+ throw new ValidationException (sprintf ("Invalid action %s, valid actions are %s " , $ action , implode (', ' , self ::ValidActions)));
103+ }
104+ $ this ->action = $ action ;
105+ $ this ->user_id = $ user_id ;
106+ $ this ->user_email = $ user_email ;
107+ $ this ->user_name = $ user_name ;
108+ $ this ->group_id = $ group_id ;
109+ $ this ->group_name = $ group_name ;
110+ $ this ->group_slug = $ group_slug ;
111+
112+ Log::debug
113+ (
114+ sprintf
115+ (
116+ "NotifyMonitoredSecurityGroupActivity::constructor action %s user_id %s user_email %s user_name %s group_id %s group_name %s group_slug %s " ,
117+ $ action ,
118+ $ user_id ,
119+ $ user_email ,
120+ $ user_name ,
121+ $ group_id ,
122+ $ group_name ,
123+ $ group_slug
124+ )
125+ );
126+ }
127+
128+ /**
129+ * @param IUserService $service
130+ * @return void
131+ */
132+ public function handle (IUserService $ service ){
133+ Log::debug
134+ (
135+ sprintf
136+ (
137+ "NotifyMonitoredSecurityGroupActivity::handle action %s user_id %s user_email %s user_name %s group_id %s group_name %s group_slug %s " ,
138+ $ this ->action ,
139+ $ this ->user_id ,
140+ $ this ->user_email ,
141+ $ this ->user_name ,
142+ $ this ->group_id ,
143+ $ this ->group_name ,
144+ $ this ->group_slug
145+ )
146+ );
147+
148+ $ service ->notifyMonitoredSecurityGroupActivity
149+ (
150+ $ this ->action ,
151+ $ this ->user_id ,
152+ $ this ->user_email ,
153+ $ this ->user_name ,
154+ $ this ->group_id ,
155+ $ this ->group_name ,
156+ $ this ->group_slug
157+ );
158+
159+ }
160+
161+ public function failed (\Throwable $ exception )
162+ {
163+ Log::error (sprintf ( "NotifyMonitoredSecurityGroupActivity::failed %s " , $ exception ->getMessage ()));
164+ }
165+ }
0 commit comments