diff options
author | Ben Hutchings <ben.hutchings@codethink.co.uk> | 2020-07-14 23:50:58 +0100 |
---|---|---|
committer | Ben Hutchings <ben.hutchings@codethink.co.uk> | 2020-07-15 17:36:44 +0100 |
commit | bc7f80d39b0bd8dd1484567b89c2e8801754d077 (patch) | |
tree | a3375eb3432c6c126271ec26f3ef79b776f1c25a | |
parent | 755dc86c41392c7065440d147258befbbeb5c1ee (diff) | |
download | lorry-controller-bc7f80d39b0bd8dd1484567b89c2e8801754d077.tar.gz |
givemejob: Move upstream host metadata lookup out of get_repo_metadata
In preparation for adding metadata for single repositories, move the
code for looking up metadata through the Upstream Host connector into
a separate function.
-rw-r--r-- | lorrycontroller/givemejob.py | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/lorrycontroller/givemejob.py b/lorrycontroller/givemejob.py index 8f4a2a8..721b55e 100644 --- a/lorrycontroller/givemejob.py +++ b/lorrycontroller/givemejob.py @@ -65,12 +65,9 @@ class GiveMeJob(lorrycontroller.LorryControllerRoute): due = lorry_info['last_run'] + lorry_info['interval'] return (lorry_info['running_job'] is None and due <= now) - def get_repo_metadata(self, statedb, lorry_info): - '''Get repository head and description.''' - - if not lorry_info['from_host']: - return {} - + @staticmethod + def get_upstream_host_repo_metadata(lorry_info): + assert lorry_info['from_host'] assert lorry_info['from_path'] try: @@ -79,14 +76,25 @@ class GiveMeJob(lorrycontroller.LorryControllerRoute): # XXX Shouldn't happen, but currently the database schema # does not prevent it return {} - - metadata = lorrycontroller.get_upstream_host(host_info) \ + else: + return lorrycontroller.get_upstream_host(host_info) \ .get_repo_metadata(lorry_info['from_path']) - if 'description' in metadata: + + def get_repo_metadata(self, statedb, lorry_info): + '''Get repository head and description.''' + + host_name = lorry_info['from_host'] + if host_name: + metadata = self.get_upstream_host_repo_metadata(lorry_info) + else: + metadata = {} + + if host_name and 'description' in metadata: # Prepend Upstream Host name metadata['description'] = '{host}: {desc}'.format( - host=lorry_info['from_host'], + host=host_name, desc=metadata['description']) + return metadata def give_job_to_minion(self, statedb, lorry_info, now): |