1616# noinspection PyPackageRequirements
1717import websocket
1818import getpass
19- import threading
2019from threading import Thread
2120import traceback
2221from bodyfetcher import BodyFetcher
3433# noinspection PyPackageRequirements
3534from tld .utils import update_tld_names , TldIOError
3635from helpers import log
36+ from tasks import Tasks
3737
3838import chatcommands
3939
121121
122122# noinspection PyProtectedMember
123123def check_socket_connections ():
124- while True :
125- time .sleep (90 )
126-
127- for client in chatcommunicate ._clients .values ():
128- if client .last_activity :
129- if (datetime .utcnow () - client .last_activity ).total_seconds () >= 60 :
130- os ._exit (10 )
131-
132-
133- Thread (name = "check socket connections" , target = check_socket_connections , daemon = True ).start ()
124+ for client in chatcommunicate ._clients .values ():
125+ if client .last_activity and (datetime .utcnow () - client .last_activity ).total_seconds () >= 60 :
126+ os ._exit (10 )
134127
135128
136129# noinspection PyProtectedMember
137- def restart_automatically (time_in_seconds ):
138- time .sleep (time_in_seconds )
139- Metasmoke .send_statistics (False ) # false indicates not to auto-repeat
130+ def restart_automatically ():
131+ Metasmoke .send_statistics ()
140132 os ._exit (1 )
141133
142134
143- Thread (name = "auto restart thread" , target = restart_automatically , args = (21600 ,)).start ()
135+ Tasks .periodic (check_socket_connections , interval = 90 )
136+ Tasks .later (restart_automatically , after = 21600 )
144137
145138log ('info' , GlobalVars .location )
146139log ('info' , GlobalVars .metasmoke_host )
@@ -155,14 +148,13 @@ def restart_automatically(time_in_seconds):
155148elif "first_start" in sys .argv and not GlobalVars .on_master :
156149 chatcommunicate .tell_rooms_with ("debug" , GlobalVars .s_reverted )
157150
158- Metasmoke .send_status_ping () # This will call itself every minute or so
159- threading .Timer (600 , Metasmoke .send_statistics ).start ()
151+ Tasks .periodic (Metasmoke .send_status_ping , interval = 60 )
152+ Tasks .periodic (Metasmoke .send_statistics , interval = 600 )
153+ Tasks .periodic (Metasmoke .check_last_pingtime , interval = 30 )
160154
161155metasmoke_ws_t = Thread (name = "metasmoke websocket" , target = Metasmoke .init_websocket )
162156metasmoke_ws_t .start ()
163157
164- Metasmoke .check_last_pingtime () # This will call itself every 10 seconds or so
165-
166158while True :
167159 try :
168160 a = ws .recv ()
0 commit comments