Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
MQTT-Redis
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
arjun.b
MQTT-Redis
Commits
8f014f81
Commit
8f014f81
authored
Feb 06, 2023
by
arjun.b
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
topic updated
parent
3650e464
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
9 additions
and
7 deletions
+9
-7
scripts/config/application_config.py
+1
-2
scripts/config/redis_connection.py
+2
-1
scripts/core/handlers/assign_patient.py
+2
-1
scripts/core/handlers/get_next_doctor.py
+2
-1
scripts/services/publisher.py
+2
-2
No files found.
scripts/config/application_config.py
View file @
8f014f81
import
configparser
import
configparser
from
scripts.logging.logging
import
logger
try
:
try
:
config
=
configparser
.
ConfigParser
()
config
=
configparser
.
ConfigParser
()
...
@@ -14,4 +13,4 @@ try:
...
@@ -14,4 +13,4 @@ try:
redis_port
=
config
.
get
(
"redis_connect"
,
"port"
)
redis_port
=
config
.
get
(
"redis_connect"
,
"port"
)
file_name
=
config
.
get
(
"logging"
,
"file_name"
)
file_name
=
config
.
get
(
"logging"
,
"file_name"
)
except
configparser
.
NoOptionError
:
except
configparser
.
NoOptionError
:
logger
.
error
(
"could not find conf file
"
)
print
(
"could not
"
)
scripts/config/redis_connection.py
View file @
8f014f81
...
@@ -3,11 +3,12 @@ import logging
...
@@ -3,11 +3,12 @@ import logging
import
redis
import
redis
from
scripts.config.application_config
import
redis_host
,
redis_port
from
scripts.config.application_config
import
redis_host
,
redis_port
from
scripts.logging.logging
import
logger
try
:
try
:
# Connect to Redis
# Connect to Redis
r
=
redis
.
Redis
(
host
=
redis_host
,
port
=
int
(
redis_port
),
db
=
1
)
r
=
redis
.
Redis
(
host
=
redis_host
,
port
=
int
(
redis_port
),
db
=
1
)
except
Exception
as
e
:
except
Exception
as
e
:
logg
ing
.
error
(
f
'cant connect to redis {e}'
)
logg
er
.
error
(
f
'cant connect to redis {e}'
)
print
(
str
(
e
))
print
(
str
(
e
))
scripts/core/handlers/assign_patient.py
View file @
8f014f81
...
@@ -7,7 +7,7 @@ from scripts.logging.logging import logger
...
@@ -7,7 +7,7 @@ from scripts.logging.logging import logger
broker
=
hostname
broker
=
hostname
port
=
int
(
port_num
)
port
=
int
(
port_num
)
topic
=
topic_name
#
topic = topic_name
client
=
mqtt_client
.
Client
()
client
=
mqtt_client
.
Client
()
client
.
connect
(
broker
,
port
,
60
)
client
.
connect
(
broker
,
port
,
60
)
...
@@ -30,6 +30,7 @@ def assign_patient(patient, doctors):
...
@@ -30,6 +30,7 @@ def assign_patient(patient, doctors):
# Assign the patient to the next doctor
# Assign the patient to the next doctor
patient
.
update
({
"doctor"
:
next_doctor
})
patient
.
update
({
"doctor"
:
next_doctor
})
r
.
hset
(
patient
[
'patient_id'
],
'doctor'
,
next_doctor
)
r
.
hset
(
patient
[
'patient_id'
],
'doctor'
,
next_doctor
)
topic
=
f
"hospital/{next_doctor}"
client
.
publish
(
topic
,
json
.
dumps
(
patient
))
client
.
publish
(
topic
,
json
.
dumps
(
patient
))
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
error
(
f
"could not assign patient: {e}"
)
logger
.
error
(
f
"could not assign patient: {e}"
)
scripts/core/handlers/get_next_doctor.py
View file @
8f014f81
import
logging
import
logging
from
scripts.config.redis_connection
import
r
from
scripts.config.redis_connection
import
r
from
scripts.logging.logging
import
logger
def
get_next_doctor
(
doctors
):
def
get_next_doctor
(
doctors
):
...
@@ -13,4 +14,4 @@ def get_next_doctor(doctors):
...
@@ -13,4 +14,4 @@ def get_next_doctor(doctors):
# Return the next doctor
# Return the next doctor
return
doctors
[
current_doctor
]
return
doctors
[
current_doctor
]
except
Exception
as
e
:
except
Exception
as
e
:
logg
ing
.
error
(
f
'cant find next doctor:{e}'
)
logg
er
.
error
(
f
'cant find next doctor:{e}'
)
scripts/services/publisher.py
View file @
8f014f81
import
logging
from
fastapi
import
FastAPI
from
fastapi
import
FastAPI
from
scripts.core.handlers.publisher_handler
import
PublishHandler
from
scripts.core.handlers.publisher_handler
import
PublishHandler
from
scripts.logging.logging
import
logger
from
scripts.model.patients
import
patients
from
scripts.model.patients
import
patients
from
scripts.constants.end_points
import
EndPoints
from
scripts.constants.end_points
import
EndPoints
app
=
FastAPI
()
app
=
FastAPI
()
...
@@ -16,5 +16,5 @@ def publish_data(details: patients):
...
@@ -16,5 +16,5 @@ def publish_data(details: patients):
try
:
try
:
PublishHandler
.
main_handler
(
details
)
PublishHandler
.
main_handler
(
details
)
except
Exception
as
e
:
except
Exception
as
e
:
logg
ing
.
error
(
f
'assign a doctor and publishing the details failed: {e}'
)
logg
er
.
error
(
f
'assign a doctor and publishing the details failed: {e}'
)
return
{
"data"
:
"data published"
}
return
{
"data"
:
"data published"
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment