Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rabbitmq_agents
Manage
Activity
Members
Labels
Plan
Issues
13
Issue boards
Milestones
Wiki
Code
Merge requests
8
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
rc
rabbitmq_agents
Commits
08141d63
Commit
08141d63
authored
2 years ago
by
Eesaan Atluri
Browse files
Options
Downloads
Patches
Plain Diff
move acctmgr agent workflow out of driver script
parent
e63517fb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!147
Merge previous default branch feat-cod-rmq into main
,
!119
Feat account management
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
account_manager.py
+24
-49
24 additions, 49 deletions
account_manager.py
with
24 additions
and
49 deletions
account_manager.py
+
24
−
49
View file @
08141d63
...
...
@@ -26,78 +26,54 @@ args = parser.parse_args()
timeout
=
60
queuename
=
rc_util
.
encode_name
(
args
.
username
)
username
=
args
.
username
state
=
args
.
state
service
=
args
.
service
corr_id
=
str
(
uuid
.
uuid4
())
# Instantiate rabbitmq object
rc_rmq
=
RCRMQ
({
"
exchange
"
:
rcfg
.
Exchange
,
"
exchange_type
"
:
"
topic
"
})
callback_queue
=
rc_rmq
.
bind_queue
(
exclusive
=
True
)
msg
=
{}
msg
[
"
username
"
]
=
username
msg
[
"
state
"
]
=
state
msg
[
"
service
"
]
=
service
msg
[
"
queuename
"
]
=
queuename
# publish msg with acctmgr.{uname} routing key.
rc_rmq
.
publish_msg
(
{
"
routing_key
"
:
f
'
acctmgr.request.
{
queuename
}
'
,
"
msg
"
:
msg
,
}
)
if
state
==
'
blocked
'
or
state
==
'
certification
'
:
action
=
"
lock
"
elif
state
==
'
ok
'
:
action
=
"
unlock
"
else
:
print
(
"
Invalid state provided. Check the help menu.
"
)
if
args
.
service
==
'
all
'
:
# send a broadcast message to all agents
rc_rmq
.
publish_msg
(
{
"
routing_key
"
:
f
"
{
action
}
.
{
username
}
"
,
"
props
"
:
pika
.
BasicProperties
(
correlation_id
=
corr_id
,
reply_to
=
callback_queue
),
"
msg
"
:
{
"
username
"
:
username
,
"
action
"
:
action
,
"
service
"
:
service
},
}
)
else
:
for
each_service
in
service
:
rc_rmq
.
publish_msg
(
{
"
routing_key
"
:
f
"
{
each_service
}
.
{
username
}
"
,
"
props
"
:
pika
.
BasicProperties
(
correlation_id
=
corr_id
,
reply_to
=
callback_queue
),
"
msg
"
:
{
"
username
"
:
username
,
"
action
"
:
action
,
"
service
"
:
service
},
}
)
def
timeout_handler
(
signum
,
frame
):
print
(
"
Process timeout, there
'
s some issue with agents
"
)
rc_rmq
.
stop_consume
()
def
callback
(
ch
annel
,
method
,
properties
,
body
):
def
callback
(
ch
,
method
,
properties
,
body
):
msg
=
json
.
loads
(
body
)
username
=
msg
[
"
username
"
]
# Check if each task returned success
for
each_task
in
msg
[
"
success
"
].
values
():
if
each_task
==
True
:
success
=
True
else
:
success
=
False
break
if
success
:
print
(
f
"
Account for
{
username
}
has been
{
action
}
ed.
\n
Updating the user state in DB
"
)
rc_util
.
update_state
(
username
,
state
)
print
(
msg
)
if
msg
[
"
success
"
]:
print
(
f
"
Account for
{
username
}
has been
{
msg
[
'
action
'
]
}
ed.
\n
Updating the user state in DB
"
)
else
:
print
(
f
"
There
'
s some issue in account management agents for
{
username
}
"
)
errmsg
=
msg
.
get
(
"
errmsg
"
,
[])
for
err
in
errmsg
:
print
(
err
)
ch
.
basic_ack
(
delivery_tag
=
method
.
delivery_tag
)
rc_rmq
.
stop_consume
()
rc_rmq
.
d
isconnect
(
)
rc_rmq
.
d
elete_queue
(
queuename
)
print
(
f
"
{
action
}
action for
{
args
.
username
}
reques
te
d
.
"
)
print
(
f
"
Request
{
username
}
account state set to
{
sta
te
}
.
"
)
# Set initial timeout timer
signal
.
signal
(
signal
.
SIGALRM
,
timeout_handler
)
...
...
@@ -106,9 +82,8 @@ signal.setitimer(signal.ITIMER_REAL, timeout)
print
(
"
Waiting for completion...
"
)
rc_rmq
.
start_consume
(
{
"
queue
"
:
callback_queue
,
"
exclusive
"
:
True
,
"
bind
"
:
False
,
"
queue
"
:
queuename
,
"
routing_key
"
:
f
'
certified.
{
queuename
}
'
,
"
cb
"
:
callback
,
}
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment