Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
account_init_cleanup
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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
Mitchell Moore
account_init_cleanup
Commits
f3f5d23f
Commit
f3f5d23f
authored
5 years ago
by
Mitchell Moore
Browse files
Options
Downloads
Patches
Plain Diff
implement rabbitmq casll option/script call option
parent
c10c702e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
run.py
+35
-21
35 additions, 21 deletions
run.py
with
35 additions
and
21 deletions
run.py
+
35
−
21
View file @
f3f5d23f
...
@@ -2,12 +2,11 @@
...
@@ -2,12 +2,11 @@
import
os
import
os
import
time
import
time
import
pika
import
pika
import
sys
from
flask_socketio
import
SocketIO
from
app
import
create_app
from
app
import
create_app
from
flask_socketio
import
SocketIO
from
flask
import
flash
config_name
=
os
.
getenv
(
'
FLASK_CONFIG
'
)
config_name
=
os
.
getenv
(
'
FLASK_CONFIG
'
)
app
=
create_app
(
config_name
)
app
=
create_app
(
config_name
)
...
@@ -41,6 +40,12 @@ def check_dir(user, interval):
...
@@ -41,6 +40,12 @@ def check_dir(user, interval):
return
False
return
False
def
create_account
(
username
,
fullname
,
reason
):
# Todo: Ravi's and Louis's code go here
time
.
sleep
(
5
)
return
True
@socketio.on
(
'
user connect
'
)
@socketio.on
(
'
user connect
'
)
def
handle_my_custom_event
(
json
,
methods
=
[
'
GET
'
,
'
POST
'
]):
def
handle_my_custom_event
(
json
,
methods
=
[
'
GET
'
,
'
POST
'
]):
username
=
json
[
"
user
"
]
username
=
json
[
"
user
"
]
...
@@ -51,28 +56,34 @@ def handle_my_custom_event(json, methods=['GET', 'POST']):
...
@@ -51,28 +56,34 @@ def handle_my_custom_event(json, methods=['GET', 'POST']):
def
ingest_data
(
json
,
methods
=
[
'
GET
'
,
'
POST
'
]):
def
ingest_data
(
json
,
methods
=
[
'
GET
'
,
'
POST
'
]):
print
(
time
.
strftime
(
"
%m-%d-%Y_%H:%M:%S
"
)
+
'
\t
Queue request received:
'
+
str
(
json
))
print
(
time
.
strftime
(
"
%m-%d-%Y_%H:%M:%S
"
)
+
'
\t
Queue request received:
'
+
str
(
json
))
# Begin RabbitMQ process.
# RabbitMQ Request Approach
credentials
=
pika
.
PlainCredentials
(
'
reggie
'
,
'
reggie
'
)
try
:
parameters
=
pika
.
ConnectionParameters
(
'
ood
'
,
credentials
=
pika
.
PlainCredentials
(
'
reggie
'
,
'
reggie
'
)
5672
,
parameters
=
pika
.
ConnectionParameters
(
'
ood
'
,
'
/
'
,
5672
,
credentials
)
'
/
'
,
credentials
)
connection
=
pika
.
BlockingConnection
(
parameters
)
connection
=
pika
.
BlockingConnection
(
parameters
)
channel
=
connection
.
channel
()
channel
=
connection
.
channel
()
channel
.
exchange_declare
(
exchange
=
'
direct_logs
'
,
exchange_type
=
'
direct
'
)
channel
.
exchange_declare
(
exchange
=
'
direct_logs
'
,
exchange_type
=
'
direct
'
)
node
=
sys
.
argv
[
1
]
if
len
(
sys
.
argv
)
>
1
else
'
info
'
node
=
'
ood
'
message
=
'
'
.
join
(
sys
.
argv
[
2
:])
or
'
Hello World!
'
message
=
str
(
json
)
channel
.
basic_publish
(
exchange
=
'
direct_logs
'
,
routing_key
=
node
,
body
=
message
)
print
(
"
[x] Sent %r:%r
"
%
(
node
,
message
))
connection
.
close
()
channel
.
basic_publish
(
exchange
=
'
direct_logs
'
,
routing_key
=
node
,
body
=
message
)
print
(
time
.
strftime
(
"
%m-%d-%Y_%H:%M:%S
"
)
+
'
\t
User
'
+
json
[
"
username
"
]
+
'
added to queue
'
)
socketio
.
emit
(
"
creating account
"
)
connection
.
close
()
except
Exception
as
e
:
print
(
time
.
strftime
(
"
%m-%d-%Y_%H:%M:%S
"
)
+
"
\t
Error in account creation:
"
,
e
)
socketio
.
emit
(
"
Account creation failed
"
)
# Todo: Make the remaining portion of this method in a RabbitMQ consumer
# try:
# try:
# fullname = json["fullname"]
# fullname = json["fullname"]
...
@@ -102,11 +113,14 @@ def ingest_data(json, methods=['GET', 'POST']):
...
@@ -102,11 +113,14 @@ def ingest_data(json, methods=['GET', 'POST']):
@socketio.on
(
"
validate creation
"
)
@socketio.on
(
"
validate creation
"
)
def
creation_confirmation
(
json
,
methods
=
[
'
GET
'
,
'
POST
'
]):
def
creation_confirmation
(
json
,
methods
=
[
'
GET
'
,
'
POST
'
]):
# Todo: Make this mthod in a RabbitMQ consumer
# User create Script Approach
username
=
json
[
"
username
"
]
username
=
json
[
"
username
"
]
fullname
=
json
[
"
fullname
"
]
reason
=
json
[
"
reason
"
]
if
c
heck_dir
(
username
,
10
):
if
c
reate_account
(
username
,
fullname
,
reason
):
print
(
time
.
strftime
(
"
%m-%d-%Y_%H:%M:%S
"
)
+
'
\t
Account successfully created for
'
+
username
)
print
(
time
.
strftime
(
"
%m-%d-%Y_%H:%M:%S
"
)
+
'
\t
Account successfully created for
'
+
username
)
socketio
.
emit
(
"
Account created
"
)
socketio
.
emit
(
"
Account created
"
)
else
:
else
:
...
...
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