Skip to content

Add unschedule method to remove jobs by name#89

Open
Shouryaverma19 wants to merge 2 commits into
Code-Society-Lab:mainfrom
Shouryaverma19:patch-2
Open

Add unschedule method to remove jobs by name#89
Shouryaverma19 wants to merge 2 commits into
Code-Society-Lab:mainfrom
Shouryaverma19:patch-2

Conversation

@Shouryaverma19

Copy link
Copy Markdown

No description provided.

@PenguinBoi12

Copy link
Copy Markdown
Contributor

@Shouryaverma19 please add a description that explains the changes you made.

@PenguinBoi12 PenguinBoi12 linked an issue Jul 3, 2026 that may be closed by this pull request
@PenguinBoi12 PenguinBoi12 added the feature A new feature label Jul 3, 2026
@PenguinBoi12 PenguinBoi12 requested a review from chrisdedman July 3, 2026 19:45

@chrisdedman chrisdedman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your work. Please make sure to read my comment and make changes accordingly.

Please also make sure to add unit tests for these changes. Thank you

Comment thread matrix/scheduler.py
"""Start the scheduler."""
self.scheduler.start()

def unschedule(self, name: str) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be more logical to have this function after the schedule function rather than at the end of the file. This will ensure that whomever is reading the file can read it like a story.

Comment thread matrix/scheduler.py

def unschedule(self, name: str) -> None:
"""Remove a registered job by its name."""
self.jobs = [job for job in self.jobs if job.name != name]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you can see in line 17 of this file, the function jobs(...) has the @property decorator. This decorator turns a function into a getter with a read-only attribute. Please see this link to learn more about the decorator.

So, because of the jobs method being read-only, doing self.jobs = ... will not work and will result in an error (as you can see in the build CI). This could have been caught if you had written a unit test for it, which you should in the following commit.

You should also always run your changes locally to ensure your implementation works as expected. Running this PR locally would have also shown that this isn’t valid, as the build would have failed.

Lastly, I don’t think the list comprehension is actually doing what it is supposed to do.
Our Scheduler is a wrapper on top of the APScheduler's AsyncIOScheduler, which means we can use everything from it. Looking at the scheduler api documentation, you can see that there is the .remove_job(...) that you can use (please see APScheduler docs). Your current implementation may remove the event from the list of jobs, but it does not ensure that the job is stopped and properly removed, which, by using the handler from APSchedule, will guarantee that it does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scheduler: Add unschedule method

3 participants