Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
E
ems_collector
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ZZH
ems_collector
Commits
9e291eec
Commit
9e291eec
authored
Apr 30, 2026
by
ZZH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
opt ems collector 2026-4-30 17:57
parent
9d4ca45c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
4 deletions
+26
-4
ems.py
src/ems_water_grp/ems.py
+26
-4
No files found.
src/ems_water_grp/ems.py
View file @
9e291eec
...
...
@@ -7,8 +7,11 @@ import asyncio
import
json
import
time
import
math
import
signal
from
typing
import
Dict
,
List
,
Optional
,
Tuple
from
gmqtt
import
Client
as
MQTTClient
from
apscheduler.schedulers.asyncio
import
AsyncIOScheduler
from
apscheduler.triggers.cron
import
CronTrigger
from
utils.encrypt
import
gen_sign
from
utils.constants
import
USER_AES
...
...
@@ -234,8 +237,7 @@ class WaterGrpService:
self
.
api_client
=
WaterGrpClient
()
self
.
mqtt_client
=
None
self
.
topology_cache
=
[]
self
.
last_sync_ts
=
0
self
.
_stop_event
=
asyncio
.
Event
()
@
staticmethod
def
on_subscribe
(
client
,
mid
,
qos
,
properties
):
...
...
@@ -255,7 +257,10 @@ class WaterGrpService:
async
def
stop
(
self
):
logger
.
info
(
"Shutting down Service..."
)
self
.
_stop_event
.
set
()
await
self
.
api_client
.
close
()
if
self
.
mqtt_client
:
await
self
.
mqtt_client
.
disconnect
()
async
def
sync_once_data
(
self
):
...
...
@@ -317,7 +322,24 @@ class WaterGrpService:
await
self
.
mqtt_client
.
connect
(
SETTING
.
mqtt_host
,
SETTING
.
mqtt_port
)
await
self
.
main_loop
()
# await self.main_loop()
scheduler
=
AsyncIOScheduler
()
scheduler
.
add_job
(
self
.
sync_once_data
,
CronTrigger
(
second
=
"2"
))
scheduler
.
start
()
logger
.
info
(
"Scheduler started, job aligned to 2nd of every minute"
)
loop
=
asyncio
.
get_running_loop
()
for
sig
in
(
signal
.
SIGINT
,
signal
.
SIGTERM
):
loop
.
add_signal_handler
(
sig
,
self
.
_stop_event
.
set
)
logger
.
info
(
"Service Engine started. Waiting for stop signal..."
)
try
:
await
self
.
_stop_event
.
wait
()
except
(
KeyboardInterrupt
,
SystemExit
):
logger
.
info
(
"Service interruption received."
)
finally
:
await
self
.
stop
()
async
def
tools
():
...
...
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