当前位置: 首页>>代码示例>>Python>>正文


Python croniter.croniter方法代码示例

本文整理汇总了Python中croniter.croniter方法的典型用法代码示例。如果您正苦于以下问题:Python croniter.croniter方法的具体用法?Python croniter.croniter怎么用?Python croniter.croniter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在croniter的用法示例。


在下文中一共展示了croniter.croniter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: start

# 需要导入模块: import croniter [as 别名]
# 或者: from croniter import croniter [as 别名]
def start(self):
        """Start timed queries execution."""
        for db in self._databases:
            try:
                await db.connect()
            except DataBaseError:
                self._increment_db_error_count(db)

        for query in self._timed_queries:
            if query.interval:
                call = PeriodicCall(self._run_query, query)
                call.start(query.interval)
            else:
                call = TimedCall(self._run_query, query)
                now = datetime.now().replace(tzinfo=gettz())
                cron_iter = croniter(query.schedule, now)

                def times_iter():
                    while True:
                        delta = next(cron_iter) - time.time()
                        yield self._loop.time() + delta

                call.start(times_iter())
            self._timed_calls[query.name] = call 
开发者ID:albertodonato,项目名称:query-exporter,代码行数:26,代码来源:loop.py

示例2: collect_dags_from_db

# 需要导入模块: import croniter [as 别名]
# 或者: from croniter import croniter [as 别名]
def collect_dags_from_db(self):
        """Collects DAGs from database."""
        from airflow.models.serialized_dag import SerializedDagModel
        start_dttm = timezone.utcnow()
        self.log.info("Filling up the DagBag from database")

        # The dagbag contains all rows in serialized_dag table. Deleted DAGs are deleted
        # from the table by the scheduler job.
        self.dags = SerializedDagModel.read_all_dags()

        # Adds subdags.
        # DAG post-processing steps such as self.bag_dag and croniter are not needed as
        # they are done by scheduler before serialization.
        subdags = {}
        for dag in self.dags.values():
            for subdag in dag.subdags:
                subdags[subdag.dag_id] = subdag
        self.dags.update(subdags)

        Stats.timing('collect_db_dags', timezone.utcnow() - start_dttm) 
开发者ID:apache,项目名称:airflow,代码行数:22,代码来源:dagbag.py

示例3: is_fixed_time_schedule

# 需要导入模块: import croniter [as 别名]
# 或者: from croniter import croniter [as 别名]
def is_fixed_time_schedule(self):
        """
        Figures out if the DAG schedule has a fixed time (e.g. 3 AM).

        :return: True if the schedule has a fixed time, False if not.
        """
        now = datetime.now()
        cron = croniter(self.normalized_schedule_interval, now)

        start = cron.get_next(datetime)
        cron_next = cron.get_next(datetime)

        if cron_next.minute == start.minute and cron_next.hour == start.hour:
            return True

        return False 
开发者ID:apache,项目名称:airflow,代码行数:18,代码来源:dag.py

示例4: cron_preview

# 需要导入模块: import croniter [as 别名]
# 或者: from croniter import croniter [as 别名]
def cron_preview(request):
    schedule = request.POST.get("schedule", "")
    tz = request.POST.get("tz")
    ctx = {"tz": tz, "dates": []}

    try:
        zone = pytz.timezone(tz)
        now_local = timezone.localtime(timezone.now(), zone)

        if len(schedule.split()) != 5:
            raise ValueError()

        it = croniter(schedule, now_local)
        for i in range(0, 6):
            ctx["dates"].append(it.get_next(datetime))

        ctx["desc"] = str(ExpressionDescriptor(schedule, use_24hour_time_format=True))
    except UnknownTimeZoneError:
        ctx["bad_tz"] = True
    except:
        ctx["bad_schedule"] = True

    return render(request, "front/cron_preview.html", ctx) 
开发者ID:healthchecks,项目名称:healthchecks,代码行数:25,代码来源:views.py

示例5: backupIfNeeded

# 需要导入模块: import croniter [as 别名]
# 或者: from croniter import croniter [as 别名]
def backupIfNeeded(self, cluster_object: V1MongoClusterConfiguration) -> bool:
        """
        Checks whether a backup is needed for the cluster, backing it up if necessary.
        :param cluster_object: The cluster object from the YAML file.
        :return: Whether a backup was created or not.
        """
        now = self._utcNow()

        cluster_key = (cluster_object.metadata.name, cluster_object.metadata.namespace)
        last_backup = self._last_backups.get(cluster_key)
        next_backup = croniter(cluster_object.spec.backups.cron, last_backup, datetime).get_next() \
            if last_backup else now

        if next_backup <= now:
            self.backup(cluster_object, now)
            self._last_backups[cluster_key] = now
            return True

        logging.info("Cluster %s @ ns/%s will need a backup at %s.", cluster_object.metadata.name,
                     cluster_object.metadata.namespace, next_backup.isoformat())
        return False 
开发者ID:Ultimaker,项目名称:k8s-mongo-operator,代码行数:23,代码来源:BackupHelper.py

示例6: reschedule

# 需要导入模块: import croniter [as 别名]
# 或者: from croniter import croniter [as 别名]
def reschedule(self, name):
            state = yield from self.get(name)
            if state.manual:
                raise ValueError("Can't reschedule")
            else:
                local_offset = pytz.timezone(state.timezone).utcoffset(dt.datetime.utcnow())
                cron = croniter(state.crontab, dt.datetime.utcnow() + local_offset)
                reschedule = cron.get_next(dt.datetime) - local_offset

            with (yield from self.db.engine) as conn:
                yield from conn.execute(update(
                    Job.__table__
                ).where(
                    Job.name==name
                ).values(
                    active=True,
                    scheduled=reschedule,
                )) 
开发者ID:paultag,项目名称:moxie,代码行数:20,代码来源:database.py

示例7: read_own_cron

# 需要导入模块: import croniter [as 别名]
# 或者: from croniter import croniter [as 别名]
def read_own_cron(own_cron_filename, config):
    with open(own_cron_filename) as tsv_file:
        tsv_reader = csv.DictReader(tsv_file, delimiter='\t')
        for row in tsv_reader:
            now = datetime.datetime.now()
            cron = croniter(row['MASK'])
            # prev_run = cron.get_current(datetime.datetime)
            prev_run = cron.get_prev(datetime.datetime)
            prev_run = cron.get_next(datetime.datetime)
            diff = now - prev_run
            diff_seconds = diff.total_seconds()
            if 0.0 <= diff_seconds and diff_seconds <= 59.9:
                # print(row['submodule_name'], diff_seconds)
                # supply(row['submodule_name'], config)
                supplying_process = Process(target=supply, args=(row['submodule_name'], config))
                supplying_process.start() 
开发者ID:Fillll,项目名称:reddit2telegram,代码行数:18,代码来源:cron_app.py

示例8: next_schedules

# 需要导入模块: import croniter [as 别名]
# 或者: from croniter import croniter [as 别名]
def next_schedules(
    crontab: str, start_at: datetime, stop_at: datetime, resolution: int = 0
) -> Iterator[datetime]:
    crons = croniter.croniter(crontab, start_at - timedelta(seconds=1))
    previous = start_at - timedelta(days=1)

    for eta in crons.all_next(datetime):
        # Do not cross the time boundary
        if eta >= stop_at:
            break

        if eta < start_at:
            continue

        # Do not allow very frequent tasks
        if eta - previous < timedelta(seconds=resolution):
            continue

        yield eta
        previous = eta 
开发者ID:apache,项目名称:incubator-superset,代码行数:22,代码来源:schedules.py

示例9: within_time_constraint

# 需要导入模块: import croniter [as 别名]
# 或者: from croniter import croniter [as 别名]
def within_time_constraint(cls, alarm):
        """Check whether the alarm is within at least one of its time limits.

        If there are none, then the answer is yes.
        """
        if not alarm.time_constraints:
            return True

        now_utc = timeutils.utcnow().replace(tzinfo=pytz.utc)
        for tc in alarm.time_constraints:
            tz = pytz.timezone(tc['timezone']) if tc['timezone'] else None
            now_tz = now_utc.astimezone(tz) if tz else now_utc
            start_cron = croniter.croniter(tc['start'], now_tz)
            if cls._is_exact_match(start_cron, now_tz):
                return True
            # start_cron.cur has changed in _is_exact_match(),
            # croniter cannot recover properly in some corner case.
            start_cron = croniter.croniter(tc['start'], now_tz)
            latest_start = start_cron.get_prev(datetime.datetime)
            duration = datetime.timedelta(seconds=tc['duration'])
            if latest_start <= now_tz <= latest_start + duration:
                return True
        return False 
开发者ID:openstack,项目名称:aodh,代码行数:25,代码来源:__init__.py

示例10: calculate_next_timestamp

# 需要导入模块: import croniter [as 别名]
# 或者: from croniter import croniter [as 别名]
def calculate_next_timestamp(ptask, node, interval_tzinfo=None):
    """
    Calculate the timestamp of the next scheduled run of task ``ptask`` on node ``node``.
    We do not check if the task is even scheduled to run on the specified node.
    Malformed cron expressions may throw a ``ValueError``.

    The next timestamp is calculated based on the last time the task was run on the given node.
    If the task has never run on the node, the last update timestamp of the periodic tasks
    is used as a reference timestamp.

    :param ptask: Dictionary describing the periodic task, as from ``PeriodicTask.get()``
    :param node: Node on which the periodic task is scheduled
    :type node: unicode
    :param interval_tzinfo: Timezone in which the cron expression should be interpreted. Defaults to local time.
    :type interval_tzinfo: tzinfo
    :return: a timezone-aware (UTC) datetime object
    """
    if interval_tzinfo is None:
        interval_tzinfo = tzlocal()
    timestamp = ptask["last_runs"].get(node, ptask["last_update"])
    local_timestamp = timestamp.astimezone(interval_tzinfo)
    iterator = croniter(ptask["interval"], local_timestamp)
    next_timestamp = iterator.get_next(datetime)
    # This will again be a timezone-aware datetime, but we return a timezone-aware UTC timestamp
    return next_timestamp.astimezone(tzutc()) 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:27,代码来源:periodictask.py

示例11: _register_param

# 需要导入模块: import croniter [as 别名]
# 或者: from croniter import croniter [as 别名]
def _register_param(self):
        self.datetime = datetime.datetime.now().replace(tzinfo=pytz.FixedOffset(480))
        self.time = time.time()
        self.loop_time = self.io_loop.time()
        for fun_name, args in self.module_arg_dict.items():
            if 'crontab' in args:
                key = args['crontab']
                self.crontab_router[key]['func'] = getattr(self, fun_name)
                self.crontab_router[key]['iter'] = croniter(args['crontab'], self.datetime)
                self.crontab_router[key]['handle'] = None
            elif 'channel' in args:
                self.channel_router[args['channel']] = getattr(self, fun_name) 
开发者ID:BigBrotherTrade,项目名称:trader,代码行数:14,代码来源:__init__.py

示例12: set_periodic_task

# 需要导入模块: import croniter [as 别名]
# 或者: from croniter import croniter [as 别名]
def set_periodic_task(name, interval, nodes, taskmodule, ordering=0, options=None, active=True, id=None):
    """
    Set a periodic task configuration. If ``id`` is None, this creates a new database entry.
    Otherwise, an existing entry is overwritten. We actually ensure that such
    an entry exists and throw a ``ParameterError`` otherwise.

    This also checks if ``interval`` is a valid cron expression, and throws
    a ``ParameterError`` if it is not.

    :param name: Unique name of the periodic task
    :type name: unicode
    :param interval: Periodicity as a string in crontab format
    :type interval: unicode
    :param nodes: List of nodes on which this task should be run
    :type nodes: list of unicode
    :param taskmodule: Name of the task module
    :type taskmodule: unicode
    :param ordering: Ordering of the periodic task (>= 0). Lower numbers are executed first.
    :type ordering: int
    :param options: Additional options for the task module
    :type options: Dictionary mapping unicodes to values that can be converted to unicode or None
    :param active: Flag determining whether the periodic task is active
    :type active: bool
    :param id: ID of the existing entry, or None
    :type id: int or None
    :return: ID of the entry
    """
    try:
        croniter(interval)
    except ValueError as e:
        raise ParameterError("Invalid interval: {!s}".format(e))
    if ordering < 0:
        raise ParameterError("Invalid ordering: {!s}".format(ordering))
    if id is not None:
        # This will throw a ParameterError if there is no such entry
        get_periodic_task_by_id(id)
    periodic_task = PeriodicTask(name, active, interval, nodes, taskmodule, ordering, options, id)
    return periodic_task.id 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:40,代码来源:periodictask.py

示例13: following_schedule

# 需要导入模块: import croniter [as 别名]
# 或者: from croniter import croniter [as 别名]
def following_schedule(self, dttm):
        """
        Calculates the following schedule for this dag in UTC.

        :param dttm: utc datetime
        :return: utc datetime
        """
        if isinstance(self.normalized_schedule_interval, str):
            # we don't want to rely on the transitions created by
            # croniter as they are not always correct
            dttm = pendulum.instance(dttm)
            naive = timezone.make_naive(dttm, self.timezone)
            cron = croniter(self.normalized_schedule_interval, naive)

            # We assume that DST transitions happen on the minute/hour
            if not self.is_fixed_time_schedule():
                # relative offset (eg. every 5 minutes)
                delta = cron.get_next(datetime) - naive
                following = dttm.in_timezone(self.timezone) + delta
            else:
                # absolute (e.g. 3 AM)
                naive = cron.get_next(datetime)
                tz = pendulum.timezone(self.timezone.name)
                following = timezone.make_aware(naive, tz)
            return timezone.convert_to_utc(following)
        elif self.normalized_schedule_interval is not None:
            return timezone.convert_to_utc(dttm + self.normalized_schedule_interval) 
开发者ID:apache,项目名称:airflow,代码行数:29,代码来源:dag.py

示例14: previous_schedule

# 需要导入模块: import croniter [as 别名]
# 或者: from croniter import croniter [as 别名]
def previous_schedule(self, dttm):
        """
        Calculates the previous schedule for this dag in UTC

        :param dttm: utc datetime
        :return: utc datetime
        """
        if isinstance(self.normalized_schedule_interval, str):
            # we don't want to rely on the transitions created by
            # croniter as they are not always correct
            dttm = pendulum.instance(dttm)
            naive = timezone.make_naive(dttm, self.timezone)
            cron = croniter(self.normalized_schedule_interval, naive)

            # We assume that DST transitions happen on the minute/hour
            if not self.is_fixed_time_schedule():
                # relative offset (eg. every 5 minutes)
                delta = naive - cron.get_prev(datetime)
                previous = dttm.in_timezone(self.timezone) - delta
            else:
                # absolute (e.g. 3 AM)
                naive = cron.get_prev(datetime)
                tz = pendulum.timezone(self.timezone.name)
                previous = timezone.make_aware(naive, tz)
            return timezone.convert_to_utc(previous)
        elif self.normalized_schedule_interval is not None:
            return timezone.convert_to_utc(dttm - self.normalized_schedule_interval) 
开发者ID:apache,项目名称:airflow,代码行数:29,代码来源:dag.py

示例15: test_enqueue5

# 需要导入模块: import croniter [as 别名]
# 或者: from croniter import croniter [as 别名]
def test_enqueue5(client):
    """Test enqueue a job using cron"""

    with client.application.app_context():
        app = client.application
        app.redis.flushall()

        task_id = str(uuid4())

        data = {"image": "ubuntu", "command": "ls", "cron": "*/10 * * * *"}
        options = dict(
            data=dumps(data),
            headers={"Content-Type": "application/json"},
            follow_redirects=True,
        )

        response = client.post(f"/tasks/{task_id}/", **options)
        expect(response.status_code).to_equal(200)
        obj = loads(response.data)
        job_id = obj["jobId"]
        expect(job_id).not_to_be_null()
        expect(obj["queueJobId"]).not_to_be_null()

        res = app.redis.zcard(Queue.SCHEDULED_QUEUE_NAME)
        expect(res).to_equal(1)

        res = app.redis.zrangebyscore(
            Queue.SCHEDULED_QUEUE_NAME, "-inf", "+inf", withscores=True
        )
        expect(res).to_length(1)

        _, timestamp = res[0]

        cron = croniter("*/10 * * * *", datetime.now())
        expected = cron.get_next(datetime)
        expect(timestamp).to_equal(expected.timestamp()) 
开发者ID:fastlane-queue,项目名称:fastlane,代码行数:38,代码来源:test_enqueue.py


注:本文中的croniter.croniter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。