diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-11-29 21:50:07 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-11-29 21:50:07 +0100 |
commit | 450b1747515e8955a3617d5c3618a50d96faa5d4 (patch) | |
tree | 1e3cec82c6e963ebbc10ca164ab6368ecf318592 | |
parent | 5d311716861dbfede64d884621ca787b96e574f9 (diff) | |
parent | aaa1875e81ca589f3a78259583c9190b75038b4f (diff) | |
download | ick2-450b1747515e8955a3617d5c3618a50d96faa5d4.tar.gz |
Merge branch 'liw/python'
-rw-r--r-- | NEWS | 5 | ||||
-rwxr-xr-x | worker_manager | 33 |
2 files changed, 27 insertions, 11 deletions
@@ -28,6 +28,11 @@ Version 0.18+git, not yet released them by name. Pipeline status is per project, however, so if two project refer to the same pipeline, they can trigger it separately. +* Pipeline steps may now be implemented in Python 3. + +* Pipelines are now run in `/var/lib/ick/workspace`, and it gets + emptied when a pipeline starts to build. + Version 0.18, released 2017-11-25 ---------------------------------- diff --git a/worker_manager b/worker_manager index a480558..bf7f14e 100755 --- a/worker_manager +++ b/worker_manager @@ -103,23 +103,21 @@ class WorkerManager(cliapp.Application): elif work: self.do_work(url, name, work, self.settings['workspace']) else: - self.show_msg('Nothing to do') self.sleep_a_little() def sleep_a_little(self): secs = self.settings['sleep'] - self.show_msg('Sleeping for {} seconds'.format(secs)) time.sleep(secs) def get_work(self, url, name): get_work_url = '{}/work/{}'.format(url, name) - self.show_msg('Getting work from {}'.format(get_work_url)) headers = self.get_auth_headers() r = requests.get(get_work_url, headers=headers, verify=False) if r.status_code != 200 or not r.text: return None work = r.json() - self.show_json('Response:', work) + if work: + self.show_json('Response:', work) return work def get_auth_headers(self): @@ -207,24 +205,37 @@ class WorkerManager(cliapp.Application): s[stream_name] = data self.post_snippet(snippet_url, s) - def run_shell(shell_cmd): + def run_with_interp(argv_prefix, cmd): exit_code, _, _ = cliapp.runcmd_unchecked( - ['bash', '-xeuc', shell_cmd], + argv_prefix + [cmd], stdout_callback=lambda data: post('stdout', data), stderr_callback=lambda data: post('stderr', data), cwd=workspace, ) - end_snippet = dict(snippet) - end_snippet['exit_code'] = exit_code - self.post_snippet(snippet_url, end_snippet) return exit_code + def run_shell(shell_cmd): + return run_with_interp(['bash', '-xeuc'], shell_cmd) + + def run_python(python_cmd): + return run_with_interp(['python3', '-c'], python_cmd) + + def run_cmd(step): + logging.info('Running step: %r', step) + if 'shell' in step: + run_shell(step['shell']) + elif 'python' in step: + run_python(step['python']) + exit_code = 0 if work.get('fresh_workspace'): + logging.info('Make an empty workspace') exit_code = run_shell('find . -delete') if exit_code == 0: - shell_cmd = work['step']['shell'] - run_shell(shell_cmd) + run_cmd(work['step']) + end_snippet = dict(snippet) + end_snippet['exit_code'] = exit_code + self.post_snippet(snippet_url, end_snippet) def now(self): return time.strftime('%Y-%m-%dT%H:%M:%S') |