當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。