Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libTask.isRunning(TASK_NAME) should return taskId or array of taskIds (which is truthy) #6714

Closed
ComLock opened this issue Nov 1, 2018 · 3 comments

Comments

@ComLock
Copy link
Member

ComLock commented Nov 1, 2018

That way you don't have do use

libTask.list({
  name: TASK_NAME,
  state: 'RUNNING'
})

to get the taskId in order to get progress.

ref: https://developer.mozilla.org/en-US/docs/Glossary/Truthy

@alansemenov
Copy link
Member

I disagree with this - it's against the purpose of the isRunning method which by definition should return a boolean value. If anything, we should implement getByName method which will return the same TaskInfo object as get but for a provided name instead of taskId.

@ComLock
Copy link
Member Author

ComLock commented Nov 6, 2018

I even take it a step further, by making progress.info an object:

function progress({
	current = undefined,
	total = undefined,
	info = undefined
} = {}) {
	return _progress({
		current,
		total,
		info: info ? JSON.stringify(info) : undefined
	});
}

And then using some info property to filter tasks on:

function getTasksWithRootId({
	rootId,
	name = TASK_NAME,
	state
}) {
	const rootTasks = listTasks({
		name,
		state
	}); //log.info(toStr({rootTasks}));

	const tasksWithRootId = rootTasks.filter((rootTask) => {
		if (rootTask.progress.info) {
			const info = JSON.parse(rootTask.progress.info);
			return info.rootId === rootId;
		}
		return false;
	}); //log.info(toStr({tasksWithRootId}));
	return tasksWithRootId;
}

@alansemenov alansemenov removed their assignment Nov 7, 2018
@rymsha
Copy link
Contributor

rymsha commented Oct 16, 2020

isRunning is not that magical. It does get list of running tasks and filters in by name and id.

It is also harmful, developers may think it is cheaper to call isRunning that to call list. But it is not true.
So, keep using list and apply your own filtering.

@rymsha rymsha closed this as completed Nov 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants