Add unschedule method to remove jobs by name#89
Conversation
|
@Shouryaverma19 please add a description that explains the changes you made. |
chrisdedman
left a comment
There was a problem hiding this comment.
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
| """Start the scheduler.""" | ||
| self.scheduler.start() | ||
|
|
||
| def unschedule(self, name: str) -> None: |
There was a problem hiding this comment.
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.
|
|
||
| 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] |
There was a problem hiding this comment.
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.
No description provided.