Example #1
0
    def add_job(self, job_id, job_key, next_run_time, serialized_job):
        timestamp = datetime_to_utc_timestamp(next_run_time)
        try:
            job = ElricJob(id=job_id, job_key=job_key,
                next_run_time=datetime_to_utc_timestamp(next_run_time),
                serialized_job=serialized_job)

            self.session.add(job)
            self.session.commit()
        except IntegrityError:
            self.session.rollback()
            raise JobAlreadyExist
Example #2
0
    def update_job(self, job_id, job_key=None, next_run_time=None, serialized_job=None, status=None):
        """
            update job
            :type job_id: str
            :type job_key: str
            :type next_run_time: datetime.datetime
            :type serialized_job: str or xmlrpclib.Binary
            :type status: int
        """
        self.log.debug("update job %s next run time=%s" % (job_id, next_run_time))
        self.log.debug("job_run_time = %s" % self.job_run_time)
        if job_id not in self.job_info:
            raise JobDoesNotExist
        job_info = self.job_info[job_id]
        if job_key is not None:
            job_info['job_key'] = job_key
        if serialized_job is not None:
            job_info['serialized_job'] = serialized_job
        if status is not None:
            job_info['status'] = status

        new_timestamp = datetime_to_utc_timestamp(next_run_time)
        old_timestamp = job_info['next_timestamp']
        if new_timestamp != old_timestamp:
            old_index = self._get_job_index(job_id, old_timestamp)
            del self.job_run_time[old_index]
            new_index = self._get_job_index(job_id, new_timestamp)
            self.job_run_time.insert(new_index, (job_id, new_timestamp))

        self.log.debug("job_run_time = %s" % self.job_run_time)
Example #3
0
 def update_job(self, job_id, job_key=None, next_run_time=None, serialized_job=None, status=None):
     new_value = {}
     if job_key is not None:
         new_value['job_key'] = job_key
     if next_run_time is not None:
         new_value['next_run_time'] = datetime_to_utc_timestamp(next_run_time)
     if serialized_job is not None:
         new_value['serialized_job'] = serialized_job
     if status is not None:
         new_value['status'] = status
     self.session.query(ElricJob).filter_by(id=job_id).update(new_value)
     self.session.commit()
Example #4
0
 def get_due_jobs(self, now):
     """
         Get due jobs.
         :type now: datetime.datetime
     """
     curr_timestamp = datetime_to_utc_timestamp(now)
     for job_id, timestamp in self.job_run_time:
         if timestamp is None or timestamp > curr_timestamp:
             break
         job_info = self.job_info[job_id]
         if job_info['status'] == 0:
             yield (job_id, job_info['job_key'], job_info['serialized_job'])
Example #5
0
    def get_due_jobs(self, now):
        """
            Get due jobs.
            :type now: datetime.datetime
        """
        curr_timestamp = datetime_to_utc_timestamp(now)
        due_jobs = []
        for job_id, timestamp in self.job_run_time:
            if timestamp is None or timestamp > curr_timestamp:
                break
            job_info = self.job_info[job_id]
            due_jobs.append((job_id, job_info['job_key'], job_info['serialized_job']))

        return due_jobs
Example #6
0
 def add_job(self, job_id, job_key, next_run_time, serialized_job):
     """
         save job
         :type job_id: str
         :type job_key: str
         :type next_run_time: datetime.datetime
         :type serialized_job: str or xmlrpclib.Binary
     """
     if job_id in self.job_info:
         raise JobAlreadyExist
     next_timestamp = datetime_to_utc_timestamp(next_run_time)
     index = self._get_job_index(job_id, next_timestamp)
     self.job_run_time.insert(index, (job_id, next_timestamp))
     self.job_info[job_id] = {'serialized_job': serialized_job, 'job_key': job_key, 'status': 0,
                              'next_timestamp': next_timestamp}
Example #7
0
 def get_due_jobs(self, now):
     timestamp = datetime_to_utc_timestamp(now)
     return self.session.query(ElricJob.id, ElricJob.job_key, ElricJob.serialized_job).filter(
             and_(ElricJob.next_run_time <= timestamp, ElricJob.status == 0)).all()