Commit 908742d2 authored by Antoine Millet's avatar Antoine Millet
Browse files

Added remote call for attachment, cancel and purge in cli handler

parent 20400d59
Loading
Loading
Loading
Loading
+26 −5
Original line number Diff line number Diff line
@@ -504,7 +504,14 @@ class CliHandler(RegisteredCCHandler):
            if obj['r'] != 'job':
                errs.error(obj['id'], 'not a job')
            elif 'p' in obj:
                errs.error(obj['id'], 'cancel on remote jobs not implemented')
                sub_id = obj['id'][len(obj['p']) + 1:]
                client = self.server.get_client(obj['p'])
                try:
                    client.proxy.job_cancel(sub_id)
                except Exception as err:
                    errs.error(obj['id'], '%s' % err)
                else:
                    errs.success(obj['id'], 'job cancelled')
            else:
                try:
                    self.server.jobs.get(obj['id']).cancel()
@@ -532,7 +539,14 @@ class CliHandler(RegisteredCCHandler):
            elif obj['state'] != 'done':
                errs.error(obj['id'], 'job must be done')
            elif 'p' in obj:
                errs.error(obj['id'], 'purge on remote jobs not implemented')
                sub_id = obj['id'][len(obj['p']) + 1:]
                client = self.server.get_client(obj['p'])
                try:
                    client.proxy.job_purge(sub_id)
                except Exception as err:
                    errs.error(obj['id'], '%s' % err)
                else:
                    errs.success(obj['id'], 'job purged')
            else:
                try:
                    self.server.jobs.purge(obj['id'])
@@ -550,20 +564,27 @@ class CliHandler(RegisteredCCHandler):

        :param query: the tql query used to select jobs
        """
        objects = self.server.list(query, show=('r', 'p'), method='attachment')
        objects = self.client.list(query, show=('r', 'p'), method='attachment')
        errs = Reporter()
        for obj in objects:
            if obj['r'] != 'job':
                errs.error(obj['id'], 'not a job')
            elif 'p' in obj:
                errs.error(obj['id'], 'purge on remote jobs not implemented')
                sub_id = obj['id'][len(obj['p']) + 1:]
                client = self.server.get_client(obj['p'])
                try:
                    output = client.proxy.job_attachment(sub_id, name)
                except Exception as err:
                    errs.error(obj['id'], '%s' % err)
                else:
                    errs.success(obj['id'], 'ok', output=output)
            else:
                try:
                    output = self.server.jobs.get(obj['id']).read_attachment(name)
                except KeyError:
                    errs.error(obj['id'], 'unknown attachment')
                else:
                    errs.success(obj['id'], 'job purged', output=output)
                    errs.success(obj['id'], 'ok', output=output)

        return errs.get_dict()