-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Filter jobs with an optional parameter use_regex #4544
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
Comments
Hi, What do you instead think of the following:
The filtered search would then be available through |
Good day @Bibo-Joshi ! |
@Bibo-Joshi This is my proposition: def jobs(self, name: str) -> Tuple["Job[CCT]", ...]:
"""Returns a tuple of all *scheduled* jobs that are currently in the :class:`JobQueue`,
matching the :obj:`name` provided.
Returns:
Tuple[:class:`Job`]: Tuple of all *scheduled* jobs.
"""
pattern = compile(str(name))
return tuple(Job.from_aps_job(job) for job in self.scheduler.get_jobs() if pattern.search(job.name))
def get_jobs_by_name(self, name: str) -> Tuple["Job[CCT]", ...]:
"""Returns a tuple of all *pending/scheduled* jobs with the given name that are currently
in the :class:`JobQueue`.
Please note that the parameter :obj:`name` accepts regular expressions.
Returns:
Tuple[:class:`Job`]: Tuple of all *pending* or *scheduled* jobs matching the name.
"""
return tuple(job for job in self.jobs(name=f"^{name}$")) The parameter |
Hi, thanks for getting back. Three remarks that I see on first glance:
I suggest that you draft a PR with your edits so that we can do a proper review on the PR :) Please be sure to follow our contribution guide, especially the checklist |
FYI, I went ahead and openend #4613 |
What kind of feature are you missing? Where do you notice a shortcoming of PTB?
I want be able to filter the jobs with a partial match of the job names, but the function
get_jobs_by_name
doesn't allow it, since it does an absolute comparison between the provided name and the job's name.Describe the solution you'd like
It would be nice to be able to filter the jobs by their names with the support of regular expressions, so developers can use the same function (
get_jobs_by_name
), extending its functionality to find jobs matching the pattern in their names.Describe alternatives you've considered
I considered to use another approach, like getting the list of jobs first, and then filter it with regular expressions, but that's redundant, since everytime this logic has to be applied, a filter step has to be inserted.
Additional context
I've already implemented the functionality in my project, and it seems that it's doing its job:
Since the new parameter
use_regex
is set to False as default, the behaviour of this function for actual uses doesn't change, therefore is not a breaking change.The text was updated successfully, but these errors were encountered: