Module: tools Branch: master Commit: bed715a52443603d3425474489bb9f5d00849cd9 URL: https://gitlab.winehq.org/winehq/tools/-/commit/bed715a52443603d3425474489bb...
Author: Jeremy White jwhite@codeweavers.com Date: Tue Jul 19 08:54:14 2022 -0500
gitlab: Drop the webhook from the runner.
Let's just run at periodic intervals. This avoids some issues when multiple requests would come in together and we would try to process too frequently.
---
gitlab/gitlab-to-mail/runner.py | 57 +++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 28 deletions(-)
diff --git a/gitlab/gitlab-to-mail/runner.py b/gitlab/gitlab-to-mail/runner.py index 40acb36b..6e62c586 100755 --- a/gitlab/gitlab-to-mail/runner.py +++ b/gitlab/gitlab-to-mail/runner.py @@ -1,46 +1,47 @@ #!/usr/bin/env python3
-# runner: run gitlabtomail.py periodically, or on request +# runner: run gitlabtomail.py periodically +# Historically, we would do this on request, when we had a change +# However, when Alexandre would do a bunch of merges, that process +# could bog down. We choose to instead invoke this with a configurable poll.
-from http.server import BaseHTTPRequestHandler, HTTPServer import subprocess import sys import os +import datetime +import time
+from util import Settings
-NAME = '' -PORT = 8000 -CMD = "./gitlabtomail.py" -ARGV1 = sys.argv[1] -TIMEOUT = 600 # 10 minutes +def usage(): + print(f"Usage:") + print(f" {sys.argv[0]} name-of-cfg-file") + print(f"Will periodically run configured command at configured interval.")
-class my_handler(BaseHTTPRequestHandler): - def do_GET(self): - self.send_response(200) - self.send_header("Content-type", "text/html") - self.end_headers() - print("Request: " + self.path) - self.wfile.write(bytes("<html><body></body></html>", "utf-8")) - subprocess.call([ CMD, ARGV1 ]) +if __name__ == "__main__": + if len(sys.argv) != 2: + print("Error: you must supply only the name of a .cfg file.") + usage() + sys.exit(-1)
- def do_POST(self): - self.do_GET() - - -if __name__ == "__main__": os.chdir(os.path.dirname(sys.argv[0])) - webServer = HTTPServer((NAME, PORT), my_handler) - webServer.timeout = TIMEOUT - webServer.request_queue_size = 4 - webServer.allow_reuse_address = True - print("Server started http://%s:%s" % (NAME, PORT)) + settings = Settings(sys.argv[1]) + + if not settings.RUNNER_INTERVAL or not settings.RUNNER_COMMAND: + print(f"Error: you must supply RUNNER_INTERVAL and RUNNER_COMMAND in {sys.argv[1]}") + sys.exit(-1)
while True: + nextrun = time.time() + settings.RUNNER_INTERVAL + print("{}running {}".format(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S - '), settings.RUNNER_COMMAND)) + subprocess.call([ settings.RUNNER_COMMAND, sys.argv[1]]) try: - webServer.handle_request() + # Delay a minimum of 30 seconds + delay = nextrun - time.time() + if delay < 30: + delay = 30 + time.sleep(delay) except KeyboardInterrupt: break - subprocess.call([ CMD, ARGV1 ])
- webServer.server_close() print("Server stopped.")