def main(args, extra): result = None if not args.actions: sys.exit("Please provide an executor to list actions for, or an action.") # User has provided an executor to list actions for elif len(args.actions) == 1: # Assume looking for executor first, fall back to action on last job try: executor = get_named_executor(args.actions[0]) actions = [[x] for x in executor.get_actions()] bot.table(actions) except: queue = Queue(config_dir=args.config_dir) task = queue.get() result = task.run_action(args.actions[0]) # NEED TO DEBUG THIS FOR SLURM # user provided exec <action> <taskid> elif len(args.actions) == 2: taskid, action = args.actions queue = Queue(config_dir=args.config_dir) task = queue.get(taskid) result = task.run_action(action) # Print result to terminal if result: if isinstance(result, list): result = " ".join(result) print(result)
def test_relational(tmp_path): """Test loading and using a queue with the filesystem database. """ from qme.main import Queue config_dir = os.path.join(str(tmp_path), ".qme") queue = Queue(config_dir=config_dir, database="sqlite") assert os.path.exists(config_dir) assert queue.config_dir == config_dir assert queue.config.configfile == os.path.join(queue.config_dir, "config.ini") assert queue.database == "sqlite" assert queue.db.database == "sqlite" # Test list, empty without anything assert not queue.list() # Run a task task = queue.run("ls") assert task.executor.name == "shell" assert task.taskid.startswith("shell") assert len(queue.list()) == 1 # Rerun the task, should still only have one rerun = queue.rerun() assert rerun.taskid == task.taskid assert len(queue.list()) == 1 # queue.get should return last task, given no id lasttask = queue.get() assert lasttask.taskid == task.taskid # Run a new task newtask = queue.run("whoami") assert len(queue.list()) == 2 exports = newtask.export() # Search for tasks assert len(queue.search("ls")) > 0 # Check exports for required in ["pwd", "output", "error", "cmd", "returncode"]: assert required in exports assert exports["pwd"] == os.getcwd() assert exports["cmd"] == ["whoami"] assert exports["returncode"] == 0 # Get a task id that isn't the last task notlast = queue.get(task.taskid) assert task.taskid == notlast.taskid # Clean up a specific task (no prompt) queue.clear(task.taskid, noprompt=True) assert len(queue.list()) == 1 queue.clear(noprompt=True) assert not queue.list()
def main(args, extra): # Create a queue object queue = Queue(config_dir=args.config_dir) task = queue.get(args.taskid) print(json.dumps(task.load(), indent=4))