Ejemplo n.º 1
0
def test_cron_trigger_1():
    trigger = CronTrigger(year='2009/2', month='1/3', day='5-13')
    eq_(repr(trigger), "<CronTrigger (year='2009/2', month='1/3', day='5-13')>")
    eq_(str(trigger), "cron[year='2009/2', month='1/3', day='5-13']")
    start_date = datetime(2008, 12, 1)
    correct_next_date = datetime(2009, 1, 5)
    eq_(trigger.get_next_fire_time(start_date), correct_next_date)
Ejemplo n.º 2
0
def test_cron_weekday_positional():
    trigger = CronTrigger(year=2009, month=1, day='4th wed')
    eq_(repr(trigger), "<CronTrigger (year='2009', month='1', day='4th wed')>")
    eq_(str(trigger), "cron[year='2009', month='1', day='4th wed']")
    start_date = datetime(2009, 1, 1)
    correct_next_date = datetime(2009, 1, 28)
    eq_(trigger.get_next_fire_time(start_date), correct_next_date)
Ejemplo n.º 3
0
def test_cron_weekday_positional():
    trigger = CronTrigger(year=2009, month=1, day='4th wed')
    eq_(repr(trigger), "<CronTrigger (year='2009', month='1', day='4th wed')>")
    eq_(str(trigger), "cron[year='2009', month='1', day='4th wed']")
    start_date = datetime(2009, 1, 1)
    correct_next_date = datetime(2009, 1, 28)
    eq_(trigger.get_next_fire_time(start_date), correct_next_date)
Ejemplo n.º 4
0
def test_cron_weekday_nomatch():
    trigger = CronTrigger(year=2009, month=1, day='6-10', day_of_week='0,6')
    eq_(repr(trigger), "<CronTrigger (year='2009', month='1', day='6-10', day_of_week='0,6')>")
    eq_(str(trigger), "cron[year='2009', month='1', day='6-10', day_of_week='0,6']")
    start_date = datetime(2009, 1, 1)
    correct_next_date = None
    eq_(trigger.get_next_fire_time(start_date), correct_next_date)
Ejemplo n.º 5
0
def test_cron_year_list():
    trigger = CronTrigger(year='2009,2008')
    eq_(repr(trigger), "<CronTrigger (year='2009,2008')>")
    eq_(str(trigger), "cron[year='2009,2008']")
    start_date = datetime(2009, 1, 1)
    correct_next_date = datetime(2009, 1, 1)
    eq_(trigger.get_next_fire_time(start_date), correct_next_date)
Ejemplo n.º 6
0
def test_week_1():
    trigger = CronTrigger(year=2009, month=2, week=8)
    eq_(repr(trigger), "<CronTrigger (year='2009', month='2', week='8')>")
    eq_(str(trigger), "cron[year='2009', month='2', week='8']")
    start_date = datetime(2009, 1, 1)
    correct_next_date = datetime(2009, 2, 16)
    eq_(trigger.get_next_fire_time(start_date), correct_next_date)
Ejemplo n.º 7
0
def test_cron_year_list():
    trigger = CronTrigger(year='2009,2008')
    eq_(repr(trigger), "<CronTrigger (year='2009,2008')>")
    eq_(str(trigger), "cron[year='2009,2008']")
    start_date = datetime(2009, 1, 1)
    correct_next_date = datetime(2009, 1, 1)
    eq_(trigger.get_next_fire_time(start_date), correct_next_date)
Ejemplo n.º 8
0
def test_week_2():
    trigger = CronTrigger(year=2009, week=15, day_of_week=2)
    eq_(repr(trigger), "<CronTrigger (year='2009', week='15', day_of_week='2')>")
    eq_(str(trigger), "cron[year='2009', week='15', day_of_week='2']")
    start_date = datetime(2009, 1, 1)
    correct_next_date = datetime(2009, 4, 8)
    eq_(trigger.get_next_fire_time(start_date), correct_next_date)
Ejemplo n.º 9
0
def test_week_1():
    trigger = CronTrigger(year=2009, month=2, week=8)
    eq_(repr(trigger), "<CronTrigger (year='2009', month='2', week='8')>")
    eq_(str(trigger), "cron[year='2009', month='2', week='8']")
    start_date = datetime(2009, 1, 1)
    correct_next_date = datetime(2009, 2, 16)
    eq_(trigger.get_next_fire_time(start_date), correct_next_date)
Ejemplo n.º 10
0
def test_cron_trigger_1():
    trigger = CronTrigger(year='2009/2', month='1/3', day='5-13')
    eq_(repr(trigger), "<CronTrigger (year='2009/2', month='1/3', day='5-13')>")
    eq_(str(trigger), "cron[year='2009/2', month='1/3', day='5-13']")
    start_date = datetime(2008, 12, 1)
    correct_next_date = datetime(2009, 1, 5)
    eq_(trigger.get_next_fire_time(start_date), correct_next_date)
Ejemplo n.º 11
0
def test_week_2():
    trigger = CronTrigger(year=2009, week=15, day_of_week=2)
    eq_(repr(trigger), "<CronTrigger (year='2009', week='15', day_of_week='2')>")
    eq_(str(trigger), "cron[year='2009', week='15', day_of_week='2']")
    start_date = datetime(2009, 1, 1)
    correct_next_date = datetime(2009, 4, 8)
    eq_(trigger.get_next_fire_time(start_date), correct_next_date)
Ejemplo n.º 12
0
def test_cron_start_date():
    trigger = CronTrigger(year='2009', month='2', hour='8-10',
                          start_date='2009-02-03 11:00:00')
    eq_(repr(trigger), "<CronTrigger (year='2009', month='2', hour='8-10', start_date='2009-02-03 11:00:00')>")
    eq_(str(trigger), "cron[year='2009', month='2', hour='8-10']")
    start_date = datetime(2009, 1, 1)
    correct_next_date = datetime(2009, 2, 4, 8)
    eq_(trigger.get_next_fire_time(start_date), correct_next_date)
Ejemplo n.º 13
0
def test_cron_extra_coverage():
    # This test has no value other than patching holes in test coverage
    trigger = CronTrigger(day='6,8')
    eq_(repr(trigger), "<CronTrigger (day='6,8')>")
    eq_(str(trigger), "cron[day='6,8']")
    start_date = datetime(2009, 12, 31)
    correct_next_date = datetime(2010, 1, 6)
    eq_(trigger.get_next_fire_time(start_date), correct_next_date)
Ejemplo n.º 14
0
def test_cron_extra_coverage():
    # This test has no value other than patching holes in test coverage
    trigger = CronTrigger(day='6,8')
    eq_(repr(trigger), "<CronTrigger (day='6,8')>")
    eq_(str(trigger), "cron[day='6,8']")
    start_date = datetime(2009, 12, 31)
    correct_next_date = datetime(2010, 1, 6)
    eq_(trigger.get_next_fire_time(start_date), correct_next_date)
Ejemplo n.º 15
0
def test_cron_increment_weekday():
    # Makes sure that incrementing the weekday field in the process of
    # calculating the next matching date won't cause problems
    trigger = CronTrigger(hour='5-6')
    eq_(repr(trigger), "<CronTrigger (hour='5-6')>")
    eq_(str(trigger), "cron[hour='5-6']")
    start_date = datetime(2009, 9, 25, 7)
    correct_next_date = datetime(2009, 9, 26, 5)
    eq_(trigger.get_next_fire_time(start_date), correct_next_date)
Ejemplo n.º 16
0
def test_cron_increment_weekday():
    # Makes sure that incrementing the weekday field in the process of
    # calculating the next matching date won't cause problems
    trigger = CronTrigger(hour='5-6')
    eq_(repr(trigger), "<CronTrigger (hour='5-6')>")
    eq_(str(trigger), "cron[hour='5-6']")
    start_date = datetime(2009, 9, 25, 7)
    correct_next_date = datetime(2009, 9, 26, 5)
    eq_(trigger.get_next_fire_time(start_date), correct_next_date)
Ejemplo n.º 17
0
def test_cron_start_date():
    trigger = CronTrigger(year='2009', month='2', hour='8-10',
                          start_date='2009-02-03 11:00:00')
    eq_(repr(trigger),
        "<CronTrigger (year='2009', month='2', hour='8-10', "
        "start_date='2009-02-03 11:00:00')>")
    eq_(str(trigger), "cron[year='2009', month='2', hour='8-10']")
    start_date = datetime(2009, 1, 1)
    correct_next_date = datetime(2009, 2, 4, 8)
    eq_(trigger.get_next_fire_time(start_date), correct_next_date)
Ejemplo n.º 18
0
def test_cron_weekday_nomatch():
    trigger = CronTrigger(year=2009, month=1, day='6-10', day_of_week='0,6')
    eq_(
        repr(trigger), "<CronTrigger (year='2009', month='1', "
        "day='6-10', day_of_week='0,6')>")
    eq_(str(trigger),
        "cron[year='2009', month='1', day='6-10', day_of_week='0,6']")
    start_date = datetime(2009, 1, 1)
    correct_next_date = None
    eq_(trigger.get_next_fire_time(start_date), correct_next_date)
Ejemplo n.º 19
0
    def add_cron_job(self, func, year=None, month=None, day=None, week=None,
                     day_of_week=None, hour=None, minute=None, second=None,
                     start_date=None, args=None, kwargs=None, **options):
        """
        Schedules a job to be completed on times that match the given
        expressions.
        Any extra keyword arguments are passed along to the constructor of the
        :class:`~apscheduler.job.Job` class (see :ref:`job_options`).

        :param func: callable to run
        :param year: year to run on
        :param month: month to run on
        :param day: day of month to run on
        :param week: week of the year to run on
        :param day_of_week: weekday to run on (0 = Monday)
        :param hour: hour to run on
        :param second: second to run on
        :param args: list of positional arguments to call func with
        :param kwargs: dict of keyword arguments to call func with
        :param name: name of the job
        :param jobstore: alias of the job store to add the job to
        :param misfire_grace_time: seconds after the designated run time that
            the job is still allowed to be run
        :return: the scheduled job
        :rtype: :class:`~apscheduler.job.Job`
        """
        trigger = CronTrigger(year=year, month=month, day=day, week=week,
                              day_of_week=day_of_week, hour=hour,
                              minute=minute, second=second,
                              start_date=start_date)
        return self.add_job(trigger, func, args, kwargs, **options)
Ejemplo n.º 20
0
 def add_cron_job(self, key, jobname, func, year=None, month=None, day=None, week=None,
                  day_of_week=None, hour=None, minute=None, second=None,
                  start_date=None, args=None, kwargs=None, **options):
     if '' == jobname.strip():
         return
     trigger = CronTrigger(year=year, month=month, day=day, week=week,
                           day_of_week=day_of_week, hour=hour,
                           minute=minute, second=second,
                           start_date=start_date)
     return self.add_job(key, jobname, trigger, func, args, kwargs, **options)
Ejemplo n.º 21
0
    def load_jobs(self):
        #continue standart execution
        jobs = []
        for job_dict in self.collection.find({'crecord_type': 'schedule'}):
            try:
                job = Job.__new__(Job)

                if job_dict['aaa_owner'] != 'root':
                    if job_dict['kwargs']['task'] != 'task_reporting':
                        raise ValueError(
                            "User %s isn\'t allow to run task %s" %
                            (job_dict['aaa_owner'],
                             job_dict['kwargs']['task']))

                #keep memory of id
                job_dict_id = job_dict['_id']

                job_dict['id'] = job_dict.pop('_id')

                if job_dict.has_key('runs'):
                    job_dict['runs'] = job_dict['runs']
                else:
                    job_dict['runs'] = 0

                job_dict['coalesce'] = False

                #try to get interval
                try:
                    if job_dict['interval'] != None:
                        job_dict['trigger'] = IntervalTrigger(
                            timedelta(**job_dict['interval']))
                except Exception, err:
                    pass

                #try to get simple
                try:
                    if job_dict['date'] != None:
                        job_dict['trigger'] = SimpleTrigger(
                            datetime(*job_dict['date']))
                except Exception, err:
                    pass

                #try to get crontab
                try:
                    if job_dict['cron'] != None:
                        job_dict['trigger'] = CronTrigger(**job_dict['cron'])
                except Exception, err:
                    pass
Ejemplo n.º 22
0
    def add_cron_job(self, func, year='*', month='*', day='*', week='*',
                     day_of_week='*', hour='*', minute='*', second='*',
                     args=None, kwargs=None):
        """
        Adds a job to be completed on times that match the given expressions.

        :param func: callable to run
        :param year: year to run on
        :param month: month to run on (0 = January)
        :param day: day of month to run on
        :param week: week of the year to run on
        :param day_of_week: weekday to run on (0 = Monday)
        :param hour: hour to run on
        :param second: second to run on
        :param args: list of positional arguments to call func with
        :param kwargs: dict of keyword arguments to call func with
        :return: the scheduled job
        :rtype: Job
        """
        trigger = CronTrigger(year=year, month=month, day=day, week=week,
                              day_of_week=day_of_week, hour=hour,
                              minute=minute, second=second)
        return self._add_job(trigger, func, args, kwargs)
Ejemplo n.º 23
0
	def load_jobs(self):
		#continue standart execution
		jobs = []
		for job_dict in self.collection.find({'crecord_type': 'schedule'}):
			try:
				job = Job.__new__(Job)

				if job_dict['aaa_owner'] != 'account.root':
					if job_dict['kwargs']['task'] != 'task_reporting':
						raise ValueError("User %s isn\'t allow to run task %s" % (job_dict['aaa_owner'],job_dict['kwargs']['task']))

				#keep memory of id
				job_dict_id = job_dict['_id']

				job_dict['id'] = job_dict.pop('_id')

				if job_dict.has_key('runs'):
					job_dict['runs'] = job_dict['runs']
				else:
					job_dict['runs'] = 0

				job_dict['coalesce'] = False

				#try to get interval
				interval = job_dict.get('interval')
				if interval is not None:
					job_dict[TRIGGER] = IntervalTrigger(timedelta(**interval))
				else: #try to get simple
					date = job_dict.get('date')
					if date is not None:
						job_dict[TRIGGER] = SimpleTrigger( datetime(*date))
					else: #try to get crontab
						cron = job_dict.get('cron')
						if cron is not None:
							job_dict[TRIGGER] = CronTrigger(**cron)

				if TRIGGER not in job_dict:
					raise ValueError("No interval, nor date, nor cron is given in task %s".format(job_dict['crecord_name']))

				job_dict['next_run_time'] = job_dict['trigger'].get_next_fire_time(datetime.now())
				job_dict['args'] = job_dict['args']
				job_dict['kwargs'] = job_dict['kwargs']
				job_dict['max_runs'] = None
				job_dict['max_instances'] = 3
				job_dict['name'] = job_dict['crecord_name']
				job_dict['misfire_grace_time'] = 1

				job_dict['func_ref'] = 'apschedulerlibs.aps_to_celery:launch_celery_task'

				job.__setstate__(job_dict)
				jobs.append(job)

				#change flag to true
				self.collection.update({'_id':job_dict_id},{"$set":{'loaded':True, 'next_run_time': job_dict['next_run_time']}},True)

			except Exception:
				job_name = job_dict.get('name', '(unknown)')
				logger.exception('Unable to restore job "%s"', job_name)

		logger.info(' + %s jobs loaded' % len(jobs))
		self.jobs = jobs
Ejemplo n.º 24
0
def test_cron_trigger_2():
    trigger = CronTrigger(year='2009/2', month='1/3', day='5-13')
    start_date = datetime(2009, 10, 14)
    correct_next_date = datetime(2011, 1, 5)
    eq_(trigger.get_next_fire_time(start_date), correct_next_date)
Ejemplo n.º 25
0
def test_cron_zero_value():
    trigger = CronTrigger(year=2009, month=2, hour=0)
    eq_(repr(trigger), "<CronTrigger (year='2009', month='2', hour='0')>")
Ejemplo n.º 26
0
def test_cron_trigger_4():
    trigger = CronTrigger(year='2012', month='2', day='last')
    eq_(repr(trigger), "<CronTrigger (year='2012', month='2', day='last')>")
    start_date = datetime(2012, 2, 1)
    correct_next_date = datetime(2012, 2, 29)
    eq_(trigger.get_next_fire_time(start_date), correct_next_date)
Ejemplo n.º 27
0
def test_cron_trigger_3():
    trigger = CronTrigger(year='2009', month='2', hour='8-10')
    eq_(repr(trigger), "<CronTrigger (year='2009', month='2', hour='8-10')>")
    start_date = datetime(2009, 1, 1)
    correct_next_date = datetime(2009, 2, 1, 8)
    eq_(trigger.get_next_fire_time(start_date), correct_next_date)
Ejemplo n.º 28
0
def test_cron_trigger_2():
    trigger = CronTrigger(year='2009/2', month='1/3', day='5-13')
    start_date = datetime(2009, 10, 14)
    correct_next_date = datetime(2011, 1, 5)
    eq_(trigger.get_next_fire_time(start_date), correct_next_date)
Ejemplo n.º 29
0
def test_cron_bad_kwarg():
    CronTrigger(second=0, third=1)
Ejemplo n.º 30
0
def test_cron_trigger_3():
    trigger = CronTrigger(year='2009', month='2', hour='8-10')
    eq_(repr(trigger), "<CronTrigger (year='2009', month='2', hour='8-10')>")
    start_date = datetime(2009, 1, 1)
    correct_next_date = datetime(2009, 2, 1, 8)
    eq_(trigger.get_next_fire_time(start_date), correct_next_date)
Ejemplo n.º 31
0
def test_cron_faulty_expr():
    CronTrigger(year='2009-fault')
Ejemplo n.º 32
0
def test_cron_trigger_4():
    trigger = CronTrigger(year='2012', month='2', day='last')
    eq_(repr(trigger), "<CronTrigger (year='2012', month='2', day='last')>")
    start_date = datetime(2012, 2, 1)
    correct_next_date = datetime(2012, 2, 29)
    eq_(trigger.get_next_fire_time(start_date), correct_next_date)
Ejemplo n.º 33
0
        parser.read(config)
    except ParsingError, e:
        log.error(str(e))
        return new_cron_jobs, False

    hostname = getHostname()
    conf_jobs = [(sec, dict(parser.items(sec))) for sec in parser.sections()]
    for sec in parser.sections():
        if not sec.isdigit(): continue
        job = dict(parser.items(sec))
        if hostname in [name.strip() for name in job['hostlist'].split(',')]:
            fields = job['task_interval'].split()
            try:
                trigger = CronTrigger(minute=fields[0],
                                      hour=fields[1],
                                      day=fields[2],
                                      month=fields[3],
                                      day_of_week=fields[4])
            except Exception, e:
                log.error(e.message)
                continue
            #print trigger.get_next_fire_time(datetime.now())
            new_cron_jobs[sec] = {
                'name': job['task_name'],
                'args': [unquote(job['task_content']).strip(), sec],
                'trigger': trigger
            }
    return new_cron_jobs, True


class ApolloCrond(object):