modify get_jobs, so that a jobstore name could be passed

Anonymous avatarAnonymous created an issue

In my environment, I use multiple jobstore aliases. I used to use get_jobs to know all the jobs that are scheduled, but I only needed to know which jobs were scheduled on a certain alias.

I modified get_jobs so that a jobstore alias could be passed as well. This solved my issue, and I am unsure if you would like to add this to your repo. But I figured, I will post it and you can deny it if you choose to :D.

407 def get_jobs(self, alias=None):
408 """ 409 Returns a list of all scheduled jobs. 410 411 :return: list of :class:~apscheduler.job.Job objects 412 """ 413 self._jobstores_lock.acquire() 414 try: 415 jobs = [] 416 if not alias: 417 for jobstore in itervalues(self._jobstores): 418 jobs.extend(jobstore.jobs) 419 else: 420 if alias in self._jobstores: 421 jobs.extend(self._jobstores[alias].jobs) 422 return jobs 423 finally: 424 self._jobstores_lock.release()

Comments (5)

  1. Alex Grönholm

    Seems reasonable. Next time though, preview your submissions! And preferably log in before you submit (Bitbucket has no way of blocking anons from creating new issues).

  2. Allen Sanabria

    Currently in scheduler.py in def get_jobs you have.

        def get_jobs(self):
            """
            Returns a list of all scheduled jobs.
    
            :return: list of :class:`~apscheduler.job.Job` objects
            """
            self._jobstores_lock.acquire()
            try:
                jobs = []
                for jobstore in itervalues(self._jobstores):
                    jobs.extend(jobstore.jobs)
                return jobs
            finally:
                self._jobstores_lock.release()
    

    I propose that you change it to..

        def get_jobs(self, alias=None):
            """
            Returns a list of all scheduled jobs.
    
            :return: list of :class:`~apscheduler.job.Job` objects
            """
            self._jobstores_lock.acquire()
            try:
                jobs = []
                if not alias:
                    for jobstore in itervalues(self._jobstores):
                        jobs.extend(jobstore.jobs)
                else:
                    if alias in self._jobstores:
                        jobs.extend(self._jobstores[alias].jobs)
                return jobs
            finally:
                self._jobstores_lock.release()
    
  3. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.