Skip to content

Commit

Permalink
fix: jobs getting missed
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintShit committed Nov 21, 2023
1 parent c1fd925 commit 41d603a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
14 changes: 10 additions & 4 deletions app/jobs/1_start_nodes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import json

from app import app, logger, scheduler, xray
from app.db import GetDB, crud
from app.models.node import NodeStatus
from app.utils.concurrency import threaded_function
from xray_api import exc as xray_exc

Expand All @@ -24,15 +27,18 @@ def nodes_health_check():
@app.on_event("startup")
@threaded_function
def app_startup():
config = xray.config.include_db_users()

with GetDB() as db:
node_ids = [dbnode.id for dbnode in crud.get_nodes(db=db, enabled=True)]
dbnodes = crud.get_nodes(db=db, enabled=True)
node_ids = [dbnode.id for dbnode in dbnodes]
for dbnode in dbnodes:
crud.update_node_status(db, dbnode, NodeStatus.connecting)

config = xray.config.include_db_users()

for node_id in node_ids:
xray.operations.connect_node(node_id, config)

scheduler.add_job(nodes_health_check, 'interval', seconds=20)
scheduler.add_job(nodes_health_check, 'interval', seconds=20, coalesce=True, max_instances=1)


@app.on_event("shutdown")
Expand Down
4 changes: 2 additions & 2 deletions app/jobs/review_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def review():

update_user_status(db, user, status)
xray.operations.add_user(user)

logger.info(f"User \"{user.username}\" status fixed.")


scheduler.add_job(review, 'interval', seconds=5)
scheduler.add_job(review, 'interval', seconds=10, coalesce=True, max_instances=1)
2 changes: 1 addition & 1 deletion app/utils/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class RealtimeBandwidthStat:
incoming_bytes=0, outgoing_bytes=0, incoming_packets=0, outgoing_packets=0)


@scheduler.scheduled_job('interval', seconds=1)
@scheduler.scheduled_job('interval', seconds=1, coalesce=True, max_instances=1)
def record_realtime_bandwidth() -> None:
io = psutil.net_io_counters()
rt_bw.incoming_bytes, rt_bw.bytes_recv = io.bytes_recv - rt_bw.bytes_recv, io.bytes_recv
Expand Down

0 comments on commit 41d603a

Please sign in to comment.