How to use the apscheduler.triggers.date.DateTrigger function in APScheduler

To help you get started, we’ve selected a few APScheduler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github agronholm / apscheduler / tests / test_triggers.py View on Github external
def test_dst_change(self, is_dst):
        """
        Test that DateTrigger works during the ambiguous "fall-back" DST period.

        Note that you should explicitly compare datetimes as strings to avoid the internal datetime
        comparison which would test for equality in the UTC timezone.

        """
        eastern = pytz.timezone('US/Eastern')
        run_date = eastern.localize(datetime(2013, 10, 3, 1, 5), is_dst=is_dst)

        fire_date = eastern.normalize(run_date + timedelta(minutes=55))
        trigger = DateTrigger(run_date=fire_date, timezone=eastern)
        assert str(trigger.get_next_fire_time(None, fire_date)) == str(fire_date)
github agronholm / apscheduler / tests / testjob.py View on Github external
def test_jobs_equal(self):
        assert self.job == self.job

        job2 = Job(DateTrigger(defaults, self.RUNTIME), lambda: None, [], {}, 1, False, None, None, 1)
        assert self.job != job2

        job2.id = self.job.id = 123
        eq_(self.job, job2)

        assert self.job != 'bleh'
github StackStorm / st2 / st2reactor / st2reactor / contrib / sensors / st2_timer_sensor.py View on Github external
trigger['parameters'], e, exc_info=True)
            raise  # Or should we just return?

        time_spec = trigger['parameters']
        time_zone = aps_utils.astimezone(trigger['parameters'].get('timezone'))

        time_type = None

        if trigger_type['name'] == 'st2.IntervalTimer':
            unit = time_spec.get('unit', None)
            value = time_spec.get('delta', None)
            time_type = IntervalTrigger(**{unit: value, 'timezone': time_zone})
        elif trigger_type['name'] == 'st2.DateTimer':
            # Raises an exception if date string isn't a valid one.
            dat = date_parser.parse(time_spec.get('date', None))
            time_type = DateTrigger(dat, timezone=time_zone)
        elif trigger_type['name'] == 'st2.CronTimer':
            cron = time_spec.copy()
            cron['timezone'] = time_zone

            time_type = CronTrigger(**cron)

        if hasattr(time_type, 'run_date') and datetime.now(tzutc()) > time_type.run_date:
            LOG.warning('Not scheduling expired timer: %s : %s',
                        trigger['parameters'], time_type.run_date)
        else:
            self._add_job(trigger, time_type)
github StackStorm / st2 / st2reactor / st2reactor / timer / base.py View on Github external
LOG.error('Exception scheduling timer: %s, %s', trigger['parameters'], e, exc_info=True)
            raise  # Or should we just return?

        time_spec = trigger['parameters']
        time_zone = aps_utils.astimezone(trigger['parameters'].get('timezone'))

        time_type = None

        if trigger_type['name'] == 'st2.IntervalTimer':
            unit = time_spec.get('unit', None)
            value = time_spec.get('delta', None)
            time_type = IntervalTrigger(**{unit: value, 'timezone': time_zone})
        elif trigger_type['name'] == 'st2.DateTimer':
            # Raises an exception if date string isn't a valid one.
            dat = date_parser.parse(time_spec.get('date', None))
            time_type = DateTrigger(dat, timezone=time_zone)
        elif trigger_type['name'] == 'st2.CronTimer':
            cron = time_spec.copy()
            cron['timezone'] = time_zone

            time_type = CronTrigger(**cron)

        utc_now = date_utils.get_datetime_utc_now()
        if hasattr(time_type, 'run_date') and utc_now > time_type.run_date:
            LOG.warning(
                'Not scheduling expired timer: %s : %s', trigger['parameters'], time_type.run_date
            )
        else:
            self._add_job(trigger, time_type)
        return time_type
github gxtrobot / bustag / bustag / app / schedule.py View on Github external
def start_scheduler():
    global scheduler, loop

    interval = int(APP_CONFIG.get('download.interval', 1800))
    loop = asyncio.new_event_loop()
    scheduler = AsyncIOScheduler(event_loop=loop)
    t1 = datetime.now() + timedelta(seconds=1)
    int_trigger = IntervalTrigger(seconds=interval)
    date_trigger = DateTrigger(run_date=t1)
    urls = (APP_CONFIG['download.root_path'],)
    # add for down at server start
    scheduler.add_job(download, trigger=date_trigger, args=(loop, False, urls))
    scheduler.add_job(download, trigger=int_trigger, args=(loop, False, urls))
    scheduler.start()
    asyncio.set_event_loop(loop)
    loop.run_forever()
github beer-garden / beer-garden / src / app / beer_garden / db / mongo / jobstore.py View on Github external
def construct_trigger(trigger_type: str, bg_trigger) -> BaseTrigger:
    """Convert a Beergarden trigger to an APScheduler one."""
    if trigger_type == "date":
        return DateTrigger(**bg_trigger.scheduler_kwargs)
    elif trigger_type == "interval":
        return IntervalTrigger(**bg_trigger.scheduler_kwargs)
    elif trigger_type == "cron":
        return CronTrigger(**bg_trigger.scheduler_kwargs)
    else:
        raise ValueError("Invalid trigger type %s" % trigger_type)
github BBVA / chaos-monkey-engine / chaosmonkey / api / executors_blueprint.py View on Github external
def dict_to_trigger(trigger_dict):
    """
    Returns a trigger version of the trigger json
    """
    if trigger_dict["type"] == "date":
        if "args" not in trigger_dict:
            raise APIError("Missing trigger args")
        if "date" not in trigger_dict["args"]:
            raise APIError("Invalid trigger args")

        try:
            trigger = DateTrigger(run_date=arrow.get(trigger_dict["args"]["date"]).datetime)
        except arrow.parser.ParserError:
            raise APIError("Invalid date format")

        return trigger
    else:
        raise APIError("Invalid trigger type")