Browse Source

Eagerly initialise services.

This will need to change when the config is rethought a little.
master
Chris Smith 5 years ago
parent
commit
e165197a70
2 changed files with 12 additions and 15 deletions
  1. 5
    5
      lineandsinker/services/__init__.py
  2. 7
    10
      main.py

+ 5
- 5
lineandsinker/services/__init__.py View File

@@ -30,9 +30,9 @@ def reportbot_factory():
30 30
     )
31 31
 
32 32
 
33
-factories = {
34
-    "docker": docker_factory,
35
-    "gitea": gitea_factory,
36
-    "jenkins": jenkins_factory,
37
-    "reportbot": reportbot_factory,
33
+services = {
34
+    "docker": docker_factory(),
35
+    "gitea": gitea_factory(),
36
+    "jenkins": jenkins_factory(),
37
+    "reportbot": reportbot_factory(),
38 38
 }

+ 7
- 10
main.py View File

@@ -4,7 +4,7 @@ from functools import wraps
4 4
 from flask import Flask, abort, request, Response
5 5
 
6 6
 from lineandsinker.common import get_hook_key
7
-from lineandsinker.services import gitea_factory, jenkins_factory, reportbot_factory
7
+from lineandsinker.services import services
8 8
 
9 9
 url_pattern = re.compile(
10 10
     "^/hooks/(?P<service>[^/]+)/(?P<identifier>.*)/(?P<key>[^/]+)$"
@@ -30,11 +30,8 @@ def authenticate(f):
30 30
     return wrapper
31 31
 
32 32
 
33
-jenkins_service = jenkins_factory()
34
-gitea_service = gitea_factory()
35
-reportbot_service = reportbot_factory()
36
-repos = dict((name, [ssh, clone]) for name, ssh, clone in gitea_service.get_repos())
37
-jobs = list(jenkins_service.get_jobs())
33
+repos = dict((name, [ssh, clone]) for name, ssh, clone in services["gitea"].get_repos())
34
+jobs = list(services["jenkins"].get_jobs())
38 35
 app = Flask(__name__)
39 36
 
40 37
 
@@ -58,7 +55,7 @@ def handle_hook_gitea(repo):
58 55
             if url in urls:
59 56
                 # TODO: Check branches
60 57
                 app.logger.info(f"Found matching job: {name} with URL {url}")
61
-                jenkins_service.build_job(name)
58
+                services["jenkins"].build_job(name)
62 59
 
63 60
         data = request.get_json()
64 61
         if not data["repository"]["private"]:
@@ -67,11 +64,11 @@ def handle_hook_gitea(repo):
67 64
             compare = data["compare_url"]
68 65
             pusher = data["pusher"]["login"]
69 66
 
70
-            reportbot_service.announce(
67
+            services["reportbot"].announce(
71 68
                 f"\002[git]\002 {pusher} pushed {commits} commit{'s' if commits != 1 else ''} to {repo}: {compare}"
72 69
             )
73 70
             for commit in data["commits"][:3]:
74
-                reportbot_service.announce(
71
+                services["reportbot"].announce(
75 72
                     f"\002[git]\002 {commit['id'][:10]}: {commit['message'][:100]}"
76 73
                 )
77 74
 
@@ -91,7 +88,7 @@ def handle_docker_registry():
91 88
             tag = event["target"]["tag"]
92 89
             host = event["request"]["host"]
93 90
             user = event["actor"]["name"]
94
-            reportbot_service.announce(
91
+            services["reportbot"].announce(
95 92
                 f"\002[registry]\002 New manifest pushed to {host}/{repo}:{tag} by {user}"
96 93
             )
97 94
 

Loading…
Cancel
Save