Пример #1
0
    def reschedule(self,
                   date,
                   callable_name=None,
                   content_object=None,
                   expires='7d',
                   args=None,
                   kwargs=None):
        """Schedule a clone of this job."""
        # Resolve date relative to the expected start of the current job.
        if isinstance(date, basestring):
            date = parse_timedelta(date)
        if isinstance(date, datetime.timedelta):
            date = self.time_slot_start + date

        if callable_name is None:
            callable_name = self.callable_name
        if content_object is None:
            content_object = self.content_object
        if args is None:
            args = self.args or []
        if kwargs is None:
            kwargs = self.kwargs or {}
        from django_future import schedule_job
        return schedule_job(date,
                            callable_name,
                            content_object=content_object,
                            expires=expires,
                            args=args,
                            kwargs=kwargs)
Пример #2
0
    def schedule_harvest(self):
        # Try to find the scheduled jobs for this object
        jobs = ScheduledJob.objects.filter(callable_name=self.job_callable_name,
                                 object_id=self.id,
                                 content_type__pk=ContentType.objects.get_for_model(self.__class__).id,
                                 status="scheduled")
        jobs.delete()
        
        # The harvesting is disabled, do not schedule a job
        if not self.active:
            return

        now = datetime.datetime.now()
        next_harvest_datetime = datetime.datetime.combine(now.date(), self.harvest_begin_time)
        if next_harvest_datetime < now:
            next_harvest_datetime += datetime.timedelta(days=1)
        harvest_interval = datetime.timedelta(hours=self.harvest_interval)
        while (next_harvest_datetime - now) > harvest_interval:
            next_harvest_datetime -= harvest_interval
        schedule_job(next_harvest_datetime, self.job_callable_name, content_object=self)
Пример #3
0
    def schedule_harvest(self):
        # Try to find the scheduled jobs for this object
        jobs = ScheduledJob.objects.filter(
            callable_name=self.job_callable_name,
            object_id=self.id,
            content_type__pk=ContentType.objects.get_for_model(self.__class__).id,
            status="scheduled",
        )
        jobs.delete()

        # The harvesting is disabled, do not schedule a job
        if not self.active:
            return

        now = datetime.datetime.now()
        next_harvest_datetime = datetime.datetime.combine(now.date(), self.harvest_begin_time)
        if next_harvest_datetime < now:
            next_harvest_datetime += datetime.timedelta(days=1)
        harvest_interval = datetime.timedelta(hours=self.harvest_interval)
        while (next_harvest_datetime - now) > harvest_interval:
            next_harvest_datetime -= harvest_interval
        schedule_job(next_harvest_datetime, self.job_callable_name, content_object=self)
Пример #4
0
    def reschedule(self, date, callable_name=None, content_object=None,
                   expires='7d', args=None, kwargs=None):
        """Schedule a clone of this job."""
        # Resolve date relative to the expected start of the current job.
        if isinstance(date, basestring):
            date = parse_timedelta(date)
        if isinstance(date, datetime.timedelta):
            date = self.time_slot_start + date

        if callable_name is None:
            callable_name = self.callable_name
        if content_object is None:
            content_object = self.content_object
        if args is None:
            args = self.args
        if kwargs is None:
            kwargs = self.kwargs
        from django_future import schedule_job
        return schedule_job(date, callable_name, content_object=content_object,
                            expires=expires, args=args, kwargs=kwargs)