File tree Expand file tree Collapse file tree 2 files changed +53
-45
lines changed Expand file tree Collapse file tree 2 files changed +53
-45
lines changed Original file line number Diff line number Diff line change 1+ """
2+ Helper class for start.py
3+ """
4+
5+ import threading
6+ import time
7+
8+
9+ class PeriodicTimer :
10+ """
11+ Helper class to facilitate waiting for periodic events.
12+ Requires the start() function to be called first.
13+ """
14+
15+ def __init__ (self , interval ):
16+ """
17+ :param interval: interval in seconds
18+ """
19+ self ._interval = interval
20+ self ._flag = 0
21+ self ._cv = threading .Condition ()
22+
23+ def start (self ):
24+ """
25+ Start the notification thread.
26+ """
27+ threading .Thread (target = self .run , daemon = True ).start ()
28+
29+ def run (self ):
30+ """
31+ Run the timer and notify waiting threads after each interval
32+ """
33+ while True :
34+ time .sleep (self ._interval )
35+ self .notify_all ()
36+
37+ def wait_for_tick (self ):
38+ """
39+ Wait for the next tick of the timer
40+ """
41+ with self ._cv :
42+ last_flag = self ._flag
43+ while last_flag == self ._flag :
44+ self ._cv .wait ()
45+
46+ def notify_all (self ):
47+ """
48+ Notify all listeners, possibly out of band.
49+ """
50+ with self ._cv :
51+ self ._flag ^= 1
52+ self ._cv .notify_all ()
Original file line number Diff line number Diff line change 4949from opengrok_tools .utils .exitvals import SUCCESS_EXITVAL
5050from opengrok_tools .utils .mirror import check_configuration
5151from opengrok_tools .mirror import OPENGROK_NO_MIRROR_ENV
52-
52+ from periodic_timer import PeriodicTimer
5353
5454fs_root = os .path .abspath ('.' ).split (os .path .sep )[0 ] + os .path .sep
5555if os .environ .get ('OPENGROK_TOMCAT_ROOT' ): # debug only
7575NOMIRROR_ENV_NAME = 'NOMIRROR'
7676
7777expected_token = None
78-
79-
80- class PeriodicTimer :
81- """
82- Helper class to facilitate waiting for periodic events.
83- Requires the start() function to be called first.
84- """
85- def __init__ (self , interval ):
86- """
87- :param interval: interval in seconds
88- """
89- self ._interval = interval
90- self ._flag = 0
91- self ._cv = threading .Condition ()
92-
93- def start (self ):
94- threading .Thread (target = self .run , daemon = True ).start ()
95-
96- def run (self ):
97- """
98- Run the timer and notify waiting threads after each interval
99- """
100- while True :
101- time .sleep (self ._interval )
102- self .notify_all ()
103-
104- def wait_for_tick (self ):
105- """
106- Wait for the next tick of the timer
107- """
108- with self ._cv :
109- last_flag = self ._flag
110- while last_flag == self ._flag :
111- self ._cv .wait ()
112-
113- def notify_all (self ):
114- """
115- Notify all listeners, possibly out of band.
116- """
117- with self ._cv :
118- self ._flag ^= 1
119- self ._cv .notify_all ()
120-
121-
12278periodic_timer = None
12379app = Flask (__name__ )
12480auth = HTTPTokenAuth (scheme = 'Bearer' )
You can’t perform that action at this time.
0 commit comments