Exemple #1
0
 def schedule(self, period, callable_func):
     """Schedule a new periodic job.
     
     New job will call C{callable} every C{period} seconds. If 
     C{callable} is already registered with another job,
     this function will raise an JobAlreadyScheduled exception.
     
     This method cannot be used to schedule jobs before syncdb
     has been done (i.e. for example outside a function context).
     For that you need to use C{Job.objects.schedule_post_syncdb}.
     See L{JobManager.schedule_post_syncdb}.
     
     @param period: time between runs in seconds.
     @type period: integer
     @param callable: function to call for executing the job.
     @type callable: Callable
     @return: The new L{Job} instance.
     @raise JobAlreadyScheduled: If callable is already
         called by another Job.
         
     """
     callable_name = stringify_func(callable_func)
     next_run_time = datetime.now() + timedelta(seconds=period)
     job, created = self.get_or_create(callable_name=callable_name,
                                       defaults=dict(
                                           period=period,
                                           next_run_time=next_run_time,
                                       ))
     if not created:
         raise JobAlreadyScheduled(job)
     else:
         return job
 def schedule(self, period, callable_func):
     """Schedule a new periodic job.
     
     New job will call C{callable} every C{period} seconds. If 
     C{callable} is already registered with another job,
     this function will raise an JobAlreadyScheduled exception.
     
     This method cannot be used to schedule jobs before syncdb
     has been done (i.e. for example outside a function context).
     For that you need to use C{Job.objects.schedule_post_syncdb}.
     See L{JobManager.schedule_post_syncdb}.
     
     @param period: time between runs in seconds.
     @type period: integer
     @param callable: function to call for executing the job.
     @type callable: Callable
     @return: The new L{Job} instance.
     @raise JobAlreadyScheduled: If callable is already
         called by another Job.
         
     """
     callable_name = stringify_func(callable_func)
     next_run_time = datetime.now() + timedelta(seconds=period)
     job, created = self.get_or_create(
         callable_name=callable_name,
         defaults=dict(
             period=period,
             next_run_time=next_run_time,
         )
     )
     if not created:
         raise JobAlreadyScheduled(job)
     else:
         return job
Exemple #3
0
 def unschedule(self, callable_func):
     """Removes periodic scheduling of a job.
     
     @param callable: The callable which was used to
         schedule the job.
     @type callable: Callable.
     @raise JobNotScheduled: If callable is not scheduled.
     
     """
     try:
         job = self.get(callable_name=stringify_func(callable_func))
     except self.model.DoesNotExist:
         raise JobNotScheduled(callable_func)
     job.delete()
 def unschedule(self, callable_func):
     """Removes periodic scheduling of a job.
     
     @param callable: The callable which was used to
         schedule the job.
     @type callable: Callable.
     @raise JobNotScheduled: If callable is not scheduled.
     
     """
     try:
         job = self.get(
             callable_name=stringify_func(callable_func))
     except self.model.DoesNotExist:
         raise JobNotScheduled(callable_func)
     job.delete()
Exemple #5
0
 def get_for(self, callable_func):
     """Get the job corresponding the callable."""
     return self.get(callable_name=stringify_func(callable_func))
 def get_for(self, callable_func):
     """Get the job corresponding the callable."""
     return self.get(
         callable_name=stringify_func(callable_func))