diff options
author | Lars Wirzenius <liw@liw.fi> | 2019-07-14 16:13:10 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2019-08-03 21:06:50 +0300 |
commit | 4dd2e14cd15ad2840cfc3636251802f8eb0bc9ba (patch) | |
tree | f5fd5b9be0ce316c35ad5876c925e148029474e0 /ick2/workapi.py | |
parent | 471b9d6209dc51890c7724b7b57b9121ba30af7d (diff) | |
download | ick2-4dd2e14cd15ad2840cfc3636251802f8eb0bc9ba.tar.gz |
Change: get and use tokens
Diffstat (limited to 'ick2/workapi.py')
-rw-r--r-- | ick2/workapi.py | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/ick2/workapi.py b/ick2/workapi.py index 5179f90..3eeb0fa 100644 --- a/ick2/workapi.py +++ b/ick2/workapi.py @@ -1,4 +1,4 @@ -# Copyright (C) 2017-2018 Lars Wirzenius +# Copyright (C) 2017-2019 Lars Wirzenius # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or @@ -40,24 +40,24 @@ class WorkAPI(ick2.APIbase): }, ] - def get_work(self, **kwargs): + def get_work(self, token=None, **kwargs): worker_id = self._get_client_id(**kwargs) ick2.log.log( 'trace', msg_text='Worker wants work', worker_id=worker_id) - with self._trans.modify('workers', worker_id) as worker: + with self._trans.modify(token, 'workers', worker_id) as worker: doing = worker.get('doing') if doing: ick2.log.log( 'trace', msg_text='Worker already got work', doing=doing) return doing - build_id = self._pick_build(worker_id) + build_id = self._pick_build(token, worker_id) if build_id is None: ick2.log.log('trace', msg_text='No suitable build for worker') return {} - with self._trans.modify('builds', build_id) as build: - with self._trans.modify('log', build_id) as log: + with self._trans.modify(token, 'builds', build_id) as build: + with self._trans.modify(token, 'log', build_id) as log: ick2.log.log( 'trace', msg_text='Picked build for worker', build_id=build_id, build=build.as_dict()) @@ -115,7 +115,7 @@ class WorkAPI(ick2.APIbase): raise ick2.ClientIdMissing() return client_id - def _pick_build(self, worker): + def _pick_build(self, token, worker): def on_worker(build): return build.get('worker') == worker @@ -129,7 +129,7 @@ class WorkAPI(ick2.APIbase): def is_triggered(build): return status(build) == ick2.BUILD_TRIGGERED - builds = self._trans.get_resources('builds') + builds = self._trans.get_resources(token, 'builds') return (self._find_build(builds, on_worker, is_building) or self._find_build(builds, is_triggered)) @@ -139,7 +139,7 @@ class WorkAPI(ick2.APIbase): return build['build_id'] return None - def update_work(self, update, **kwargs): + def update_work(self, update, token=None, **kwargs): try: worker_id = update['worker'] build_id = update['build_id'] @@ -148,9 +148,9 @@ class WorkAPI(ick2.APIbase): except KeyError as e: # pragma: no cover raise ick2.BadUpdate(str(e)) - with self._trans.modify('workers', worker_id) as worker: - with self._trans.modify('builds', build_id) as build: - with self._trans.modify('log', build_id) as log: + with self._trans.modify(token, 'workers', worker_id) as worker: + with self._trans.modify(token, 'builds', build_id) as build: + with self._trans.modify(token, 'log', build_id) as log: doing = worker.get('doing', {}) self._check_work_update(doing, update) self._append_to_build_log(log, update) |