Exemplo n.º 1
0
    def _reconstitute_job(self, job_state):
        schedule = job_state['schedule']
        schedule.pop('coalesce', None)
        next_run_time = job_state['next_run_time']

        if next_run_time == 1:
            # This is hacky. We need to subtract more than value of misfire_grace_time
            # so that the job will be missed right after loading it for the first time
            # after doing fresh install instead of being executed.
            next_run_time = int(time.time() - 1200)

        job = Job(id=job_state['id'],
                  func="__main__:job",
                  trigger=CronTrigger(**schedule),
                  name=job_state['name'],
                  args=[job_state['task']] + job_state['args'],
                  scheduler=self._scheduler,
                  executor='default',
                  next_run_time=utc_timestamp_to_datetime(next_run_time),
                  kwargs={
                      'id': job_state['id'],
                      'name': job_state['name'],
                      'hidden': job_state.get('hidden', False),
                      'protected': job_state.get('protected', False)
                  })

        job.coalesce = True
        job.max_instances = 1
        job.misfire_grace_time = 600
        job._jobstore_alias = self._alias
        return job
Exemplo n.º 2
0
 def get_next_run_time(self):
     document = self.ds.query('calendar_tasks',
                              ('next_run_time', '!=', None),
                              sort='next_run_time',
                              single=True)
     return utc_timestamp_to_datetime(
         document['next_run_time']) if document else None
Exemplo n.º 3
0
    def _reconstitute_job(self, job_state):
        schedule = job_state['schedule']
        schedule.pop('coalesce', None)
        next_run_time = job_state['next_run_time']

        if next_run_time == 1:
            # This is hacky. We need to subtract more than value of misfire_grace_time
            # so that the job will be missed right after loading it for the first time
            # after doing fresh install instead of being executed.
            next_run_time = int(time.time() - 1200)

        job = Job(
            id=job_state['id'],
            func="__main__:job",
            trigger=CronTrigger(**schedule),
            name=job_state['name'],
            args=[job_state['task']] + job_state['args'],
            scheduler=self._scheduler,
            executor='default',
            next_run_time=utc_timestamp_to_datetime(next_run_time),
            kwargs={
                'id': job_state['id'],
                'name': job_state['name'],
                'hidden': job_state.get('hidden', False),
                'protected': job_state.get('protected', False)
            }
        )

        job.coalesce = True
        job.max_instances = 1
        job.misfire_grace_time = 600
        job._jobstore_alias = self._alias
        return job
Exemplo n.º 4
0
 def get_next_run_time(self):
     next_run_time = self.redis.zrange(self.run_times_key,
                                       0,
                                       0,
                                       withscores=True)
     if next_run_time:
         return utc_timestamp_to_datetime(next_run_time[0][1])
Exemplo n.º 5
0
    def _reconstitute_job(self, job_state):
        schedule = job_state['schedule']
        schedule.pop('coalesce', None)
        job = Job(
            id=job_state['id'],
            func="__main__:job",
            trigger=CronTrigger(**schedule),
            name=job_state['name'],
            args=[job_state['task']] + job_state['args'],
            scheduler=self._scheduler,
            executor='default',
            next_run_time=utc_timestamp_to_datetime(job_state['next_run_time']),
            kwargs={
                'id': job_state['id'],
                'name': job_state['name'],
                'hidden': job_state.get('hidden', False),
                'protected': job_state.get('protected', False)
            }
        )

        job.coalesce = True
        job.max_instances = 1
        job.misfire_grace_time = 0
        job._jobstore_alias = self._alias
        return job
 def get_next_run_time(self):
     next_runs = [
         job_def['next_run_time'] for job_def in self._get_jobs()
         if job_def['next_run_time'] is not None
     ]
     return utc_timestamp_to_datetime(
         min(next_runs)) if len(next_runs) > 0 else None
Exemplo n.º 7
0
 def get_next_run_time(self):
     selectable = select([self.jobs_t.c.next_run_time
                          ]).where(self.jobs_t.c.next_run_time != null())
     selectable = selectable.order_by(self.jobs_t.c.next_run_time).limit(1)
     next_run_time = self.engine.execute(selectable).scalar()
     return utc_timestamp_to_datetime(
         next_run_time.timestamp()) if next_run_time else ''
Exemplo n.º 8
0
 def get_next_run_time(self) -> Optional[datetime]:
     sorted_items = self._get_sorted_items()
     for item in sorted_items:
         _next_run_time = datetime_to_utc_timestamp(item.job.next_run_time)
         if _next_run_time is not None:
             return utc_timestamp_to_datetime(_next_run_time)
     return None
Exemplo n.º 9
0
 def get_next_run_time(self):
     next_run_time = self.sess.query(
         Scheduler.next_time
     ).filter(
         Scheduler.enabled == True,
         Scheduler.next_time != None
     ).scalar()
     return utc_timestamp_to_datetime(next_run_time)
Exemplo n.º 10
0
 def get_next_run_time(self):
     document = self.collection.find_one({'next_run_time': {
         '$ne': None
     }},
                                         projection=['next_run_time'],
                                         sort=[('next_run_time', ASCENDING)
                                               ])
     return utc_timestamp_to_datetime(
         document['next_run_time']) if document else None
Exemplo n.º 11
0
    def get_next_run_time(self):
        try:
            selectable = select([self.jobs_t.c.next_run_time]).where(self.jobs_t.c.next_run_time != None).\
                order_by(self.jobs_t.c.next_run_time).limit(1)
            next_run_time = self.engine.execute(selectable).scalar()
            return utc_timestamp_to_datetime(next_run_time)
        except SQLAlchemyError as e:
            if isinstance(e.orig, InvalidRequestError):
               self.session.rollback()
            elif not isinstance(e, OperationalError):
               raise

            del self.engine 
            self.engine = create_engine(self.url)
            selectable = select([self.jobs_t.c.next_run_time]).where(self.jobs_t.c.next_run_time != None).\
                order_by(self.jobs_t.c.next_run_time).limit(1)
            next_run_time = self.engine.execute(selectable).scalar()
            return utc_timestamp_to_datetime(next_run_time)
Exemplo n.º 12
0
 def get_next_run_time(self):
     results = list(
         self.table
         .filter(r.row['next_run_time'] != None)
         .order_by(r.asc('next_run_time'))
         .map(lambda x: x['next_run_time'])
         .limit(1)
         .run(self.conn)
     )
     return utc_timestamp_to_datetime(results[0]) if results else None
Exemplo n.º 13
0
    def get_next_run_time(self):
        document = list(
            self.table.filter(lambda x: x['next_run_time'] != None).order_by(
                r.asc('next_run_time')).map(
                    lambda x: x['next_run_time']).limit(1).run(self.conn))
        if document:
            document = utc_timestamp_to_datetime(document[0])
        else:
            document = None

        return document
Exemplo n.º 14
0
 def get_next_run_time(self):
     print("get_next_run_time not yet available")
     document = self.collection.where(u'next_run_time', u'>', 0).order_by(u'next_run_time').limit(1).get()
     document = list(document)
     try:
         document = document[0].to_dict()
     except IndexError:
         document = None
     #  document = self.collection.find_one({'next_run_time': {'$ne': None}},
     #                                      projection=['next_run_time'],
     #                                      sort=[('next_run_time', ASCENDING)])
     return utc_timestamp_to_datetime(document['next_run_time']) if document else None
Exemplo n.º 15
0
 def _db_to_job(self, row):
     if row['trigger_type'] == 'date':
         trigger = DateTrigger(run_date=row['run_date'])
     if row['trigger_type'] == 'cron':
         keys = row['crontab'].split(',')[1]
         values = row['crontab'].split(',')[0].split(' ')
         cronMapRev = {v: k for k, v in cronMap.items()}
         crontab = {cronMapRev[k]: values[i] for i, k in enumerate(keys)}
         trigger = CronTrigger(**crontab)
     if row['trigger_type'] == 'interval':
         trigger = IntervalTrigger(seconds=row['interval'])
     job = Job.__new__(Job)
     job.__setstate__({
         'id':
         row['id'],
         'name':
         row['name'],
         'func':
         row['func'],
         'args':
         json.loads(row['args']) if row['args'] else [],
         'kwargs':
         json.loads(row['kwargs']) if row['kwargs'] else {},
         'version':
         1,
         'trigger':
         trigger,
         'executor':
         row['executor'],
         'start_date':
         row['start_date'],
         'end_date':
         row['end_date'],
         'next_run_time':
         utc_timestamp_to_datetime(row['next_run_time'].timestamp()),
         'coalesce':
         row['coalesce'],
         'misfire_grace_time':
         row['misfire_grace_time'],
         'max_instances':
         row['max_instances'],
         'jobstore':
         self,
     })
     job._scheduler = self._scheduler
     job._jobstore_alias = self._alias
     print(job._scheduler)
     print(job._jobstore_alias)
     return job
Exemplo n.º 16
0
    def get_next_run_time(self):
        document = list(
            self.table
            .filter(
                lambda x:
                x['next_run_time'] != None
            )
            .order_by(r.asc('next_run_time'))
            .map(lambda x: x['next_run_time'])
            .limit(1)
            .run(self.conn)
        )
        if document:
            document = utc_timestamp_to_datetime(document[0])
        else:
            document = None

        return document
Exemplo n.º 17
0
 def get_next_run_time(self):
     selectable = select([self.jobs_t.c.next_run_time]).where(self.jobs_t.c.next_run_time != None).\
         order_by(self.jobs_t.c.next_run_time).limit(1)
     next_run_time = self.engine.execute(selectable).scalar()
     return utc_timestamp_to_datetime(next_run_time)
Exemplo n.º 18
0
def test_datetime_to_utc_timestamp(timezone):
    dt = timezone.localize(datetime(2014, 3, 12, 5, 40, 13, 254012))
    timestamp = datetime_to_utc_timestamp(dt)
    dt2 = utc_timestamp_to_datetime(timestamp)
    assert dt2 == dt
Exemplo n.º 19
0
 def get_next_run_time(self):
     document = self.collection.find_one({'next_run_time': {'$ne': None}}, projection=['next_run_time'],
                                         sort=[('next_run_time', ASCENDING)])
     return utc_timestamp_to_datetime(document['next_run_time']) if document else None
Exemplo n.º 20
0
 def get_next_run_time(self):
     document = self.ds.query('calendar_tasks', ('next_run_time', '!=', None), sort='next_run_time', single=True)
     return utc_timestamp_to_datetime(document['next_run_time']) if document else None
Exemplo n.º 21
0
 def get_next_run_time(self):
     run_times = self.run_times.iterator(include_value=False)
     if run_times:
         next_run_time = float(int(run_times[0]))
         return utc_timestamp_to_datetime(next_run_time)
Exemplo n.º 22
0
 def get_next_run_time(self):
     next_runs = [job_def['next_run_time'] for job_def in self._get_jobs()
                  if job_def['next_run_time'] is not None]
     return utc_timestamp_to_datetime(min(next_runs)) if len(next_runs) > 0 else None
Exemplo n.º 23
0
Arquivo: redis.py Projeto: 2mny/mylar
 def get_next_run_time(self):
     next_run_time = self.redis.zrange(self.run_times_key, 0, 0, withscores=True)
     if next_run_time:
         return utc_timestamp_to_datetime(next_run_time[0][1])
Exemplo n.º 24
0
def test_datetime_to_utc_timestamp(timezone):
    dt = timezone.localize(datetime(2014, 3, 12, 5, 40, 13, 254012))
    timestamp = datetime_to_utc_timestamp(dt)
    dt2 = utc_timestamp_to_datetime(timestamp)
    assert dt2 == dt
Exemplo n.º 25
0
 def get_next_run_time(self):
     selectable = select([self.jobs_t.c.next_run_time]).where(self.jobs_t.c.next_run_time != None).\
         order_by(self.jobs_t.c.next_run_time).limit(1)
     next_run_time = self.engine.execute(selectable).scalar()
     return utc_timestamp_to_datetime(next_run_time)
Exemplo n.º 26
0
 def get_next_run_time(self):
     next_run_time = self.sess.query(Scheduler.next_time).filter(
         Scheduler.enabled == True, Scheduler.next_time != None).scalar()
     return utc_timestamp_to_datetime(next_run_time)
Exemplo n.º 27
0
 def get_next_run_time(self):
     selectable = self.job_model.select(self.job_model.next_run_time).\
         where(~(self.job_model.next_run_time.is_null())).\
         order_by(self.job_model.next_run_time.asc()).limit(1)
     job = selectable.first()
     return utc_timestamp_to_datetime(job.next_run_time) if job else None