81
81
REINDEX_POINT = '/reindex'
82
82
83
83
84
- def trigger_reindex ():
85
- # Signal the sync/indexer thread.
86
- periodic_timer .notify_all ()
87
-
88
-
89
84
@auth .verify_token
90
85
def verify_token (token ):
91
86
if expected_token is None :
@@ -98,9 +93,16 @@ def verify_token(token):
98
93
@app .route (REINDEX_POINT )
99
94
@auth .login_required
100
95
def index ():
101
- periodic_timer .notify_all ()
96
+ global periodic_timer
97
+
98
+ if periodic_timer :
99
+ logger = logging .getLogger (__name__ )
100
+ logger .debug ("Triggering reindex based on API call" )
102
101
103
- return "Reindex triggered"
102
+ periodic_timer .notify_all ()
103
+ return "Reindex triggered\n "
104
+
105
+ return "Reindex not triggered - the timer is not initialized yet\n "
104
106
105
107
106
108
def rest_function (logger , rest_port ):
@@ -297,7 +299,8 @@ def indexer_no_projects(logger, uri, config_path, extra_indexer_options):
297
299
indexer .execute ()
298
300
299
301
logger .info ("Waiting for reindex to be triggered" )
300
- periodic_timer .wait_for_tick ()
302
+ global periodic_timer
303
+ periodic_timer .wait_for_event ()
301
304
302
305
303
306
def project_syncer (logger , loglevel , uri , config_path , numworkers , env ):
@@ -346,7 +349,8 @@ def project_syncer(logger, loglevel, uri, config_path, numworkers, env):
346
349
save_config (logger , uri , config_path )
347
350
348
351
logger .info ("Waiting for reindex to be triggered" )
349
- periodic_timer .wait_for_tick ()
352
+ global periodic_timer
353
+ periodic_timer .wait_for_event ()
350
354
351
355
352
356
def create_bare_config (logger , use_projects , extra_indexer_options = None ):
@@ -553,6 +557,12 @@ def main():
553
557
extra_indexer_options )
554
558
555
559
if sync_enabled :
560
+ period_seconds = sync_period_mins * 60
561
+ logger .debug (f"Creating and starting periodic timer (period { period_seconds } seconds)" )
562
+ global periodic_timer
563
+ periodic_timer = PeriodicTimer (period_seconds )
564
+ periodic_timer .start ()
565
+
556
566
logger .debug ("Starting sync thread" )
557
567
sync_thread = threading .Thread (target = worker_function ,
558
568
name = "Sync thread" ,
@@ -561,11 +571,6 @@ def main():
561
571
562
572
start_rest_thread (logger )
563
573
564
- if sync_period_mins > 0 :
565
- global periodic_timer
566
- periodic_timer = PeriodicTimer (sync_period_mins * 60 )
567
- periodic_timer .start ()
568
-
569
574
# Start Tomcat last. It will be the foreground process.
570
575
logger .info ("Starting Tomcat" )
571
576
global tomcat_popen
0 commit comments