def create(self, args, config, connection): if args['json'] is not None: task = self._read(None, args['json'], args['group']) else: task = Task(connection=connection) task.create(connection=connection) print("Created task {}".format(task.id()))
def get(self, args, config, connection): task = Task(args['id'], args['group'], connection=connection) if not task.exists(): print("Error: Task does not exist: {0}".format(args['id'])) sys.exit(1) task.read() self.jprint(task)
def task(self, taskid, group="Default", connection=None): """ Get the task with a particular task-id. """ if connection is None: task = Task.lookup(self.connection, taskid, group) task.set_connection(self.connection, self.save_connection) else: task = Task.lookup(connection, taskid, group) return task
def tasks(self, connection=None): """ Get a list of the scheduled tasks. """ if connection is None: connection = self.connection return Task.list(connection)
def _read(self, task, jsonfile, group): jf = open(jsonfile).read() data = json.loads(jf) if task is not None and 'task-type' not in data: data['task-type'] = task.type() task = Task.unmarshal(data) return task
def test_minutely_task(self): beforeTasks = Task.list(self.connection) task = Task.minutely_task("/minutely.xqy", connection=self.connection) task.create() afterTasks = Task.list(self.connection) assert len(afterTasks) > len(beforeTasks) assert task.id() is not None newTask = Task.lookup(self.connection, task.id(), "Default") assert isinstance(newTask, MinutelyTask) for key in task._config: assert newTask._config[key] == task._config[key] task.set_enabled(False) task.update() task.set_period(3) try: task.update() except UnexpectedManagementAPIResponse: pass except: raise task.delete() afterTasks = Task.list(self.connection) assert len(afterTasks) == len(beforeTasks) newTask = Task.lookup(self.connection, task.id(), "Default") assert newTask is None
def modify(self, args, config, connection): task = Task.lookup(connection, args['id'], args['group']) task.set_id(args['id']) if args['json'] is not None: task = self._read(task, args['json'], args['group']) task = task.read(connection=connection) self._properties(task, args) if task.id() != args['id']: print("You cannot change the task ID") sys.exit(1) print("Modify task {}".format(task.id())) task.update(connection=connection)
def test_list_tasks(self): tasks = Task.list(self.connection) assert True
def delete(self, args, config, connection): task = Task(args['id'], args['group'], connection=connection) print("Delete task {0}...".format(args['id'])) task.delete()
def list(self, args, config, connection): names = Task.list(connection) print(json.dumps(names, sort_keys=True, indent=2))
def list(self, args, config, connection): names = Task.list(connection) print(json.dumps(names,sort_keys=True, indent=2))