File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change 4
4
import time
5
5
import json
6
6
import docker
7
+ import threading
7
8
import argparse
8
9
from argparse import ArgumentTypeError as err
9
10
from base64 import b64decode
@@ -168,6 +169,9 @@ class Handler(FileSystemEventHandler):
168
169
169
170
def __init__ (self , args ):
170
171
self .args = args
172
+ self .isWaiting = False
173
+ self .timer = threading .Timer (0.5 , self .doTheWork )
174
+ self .lock = threading .Lock ()
171
175
172
176
def on_created (self , event ):
173
177
self .handle (event )
@@ -181,10 +185,19 @@ def handle(self, event):
181
185
if not event .is_directory and event .src_path .endswith (str (self .args .certificate )):
182
186
print ('Certificates changed' )
183
187
184
- domains = createCerts (
185
- event .src_path , self .args .directory , self .args .flat )
186
- if (self .args .restart_container ):
187
- restartContainerWithDomains (domains )
188
+ with self .lock :
189
+ if not self .isWaiting :
190
+ self .isWaiting = True #trigger the work just once (multiple events get fired)
191
+ self .timer = threading .Timer (0.5 , self .doTheWork )
192
+ self .timer .start ()
193
+
194
+ def doTheWork (self ):
195
+ domains = createCerts (self .args .certificate , self .args .directory , self .args .flat )
196
+ if (self .args .restart_container ):
197
+ restartContainerWithDomains (domains )
198
+
199
+ with self .lock :
200
+ self .isWaiting = False
188
201
189
202
190
203
if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments