How to use the croniter.croniter.is_valid function in croniter

To help you get started, we’ve selected a few croniter 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 albertodonato / query-exporter / query_exporter / db.py View on Github external
def _check_schedule(self):
        if self.interval and self.schedule:
            raise InvalidQuerySchedule(
                self.name, "both interval and schedule specified"
            )
        if self.schedule and not croniter.is_valid(self.schedule):
            raise InvalidQuerySchedule(self.name, "invalid schedule format")
github apache / incubator-superset / superset / views / schedules.py View on Github external
def pre_add(self, item):
        try:
            recipients = get_email_address_list(item.recipients)
            item.recipients = ", ".join(recipients)
        except Exception:
            raise SupersetException("Invalid email list")

        item.user = item.user or g.user
        if not croniter.is_valid(item.crontab):
            raise SupersetException("Invalid crontab format")
github nebula-orchestrator / manager / manager.py View on Github external
else:
        # check the request is passed with all needed parameters
        try:
            cron_job_json = request.json
            schedule = cron_job_json["schedule"]
            env_vars = return_sane_default_if_not_declared("env_vars", cron_job_json, {})
            docker_image= cron_job_json["docker_image"]
            running = return_sane_default_if_not_declared("running", cron_job_json, True)
            networks = return_sane_default_if_not_declared("networks", cron_job_json, [])
            volumes = return_sane_default_if_not_declared("volumes", cron_job_json, [])
            devices = return_sane_default_if_not_declared("devices", cron_job_json, [])
            privileged = return_sane_default_if_not_declared("privileged", cron_job_json, False)
        except:
            return json.dumps(find_missing_params(cron_job_json, ["docker_image", "schedule"])), 400
        # check edge case where schedule is not valid
        if croniter.is_valid(schedule) is False:
            return jsonify({"schedule_valid": False}), 400
        # update the db
        cron_job_json = mongo_connection.mongo_add_cron_job(cron_job, schedule, env_vars, docker_image, running,
                                                            networks, volumes, devices, privileged)
        return dumps(cron_job_json), 200
github PrefectHQ / prefect / src / prefect / schedules.py View on Github external
def __init__(
        self, cron: str, start_date: datetime = None, end_date: datetime = None
    ):
        # build cron object to check the cron string - will raise an error if it's invalid
        if not croniter.is_valid(cron):
            raise ValueError("Invalid cron string: {}".format(cron))
        self.cron = cron
        super().__init__(start_date=start_date, end_date=end_date)
github SAP / InfraBox / src / api / handlers / projects / cronjobs.py View on Github external
def post(self, project_id):
        '''
        Create new cronjob
        '''
        b = request.get_json()

        if not CronJobs.name_pattern.match(b['name']):
            abort(400, 'CronJob name must be not empty alphanumeric string.')

        if not croniter.is_valid('%s %s %s %s %s' % (b['minute'], b['hour'], b['day_month'], b['month'], b['day_week'])):
            abort(400, 'Invalid input expression')

        result = g.db.execute_one_dict("""
            SELECT COUNT(*) as cnt FROM cronjob WHERE project_id = %s
        """, [project_id])

        if result['cnt'] > 50:
            abort(400, 'Too many cronjobs.')

        r = g.db.execute_one("""
                    SELECT count(*) FROM cronjob
                    WHERE project_id = %s AND name = %s
                """, [project_id, b['name']])

        if r[0] > 0:
            abort(400, 'CronJob with this name already exist')
github getsentry / sentry / src / sentry / api / validators / monitor.py View on Github external
if not isinstance(value, list):
                raise ValidationError("Invalid value for schedule_type")
            if not isinstance(value[0], int):
                raise ValidationError("Invalid value for schedule unit count (index 0)")
            if value[1] not in INTERVAL_NAMES:
                raise ValidationError("Invalid value for schedule unit name (index 1)")
        elif schedule_type == ScheduleType.CRONTAB:
            if not isinstance(value, six.string_types):
                raise ValidationError("Invalid value for schedule_type")
            value = value.strip()
            if value.startswith("@"):
                try:
                    value = NONSTANDARD_CRONTAB_SCHEDULES[value]
                except KeyError:
                    raise ValidationError("Schedule was not parseable")
            if not croniter.is_valid(value):
                raise ValidationError("Schedule was not parseable")
            attrs["schedule"] = value
        return attrs
github omegaml / omegaml / omegaml / notebook / jobschedule.py View on Github external
hour = self._expand_every(hour)
        weekday = self._expand_every(weekday)
        monthday = self._expand_every(monthday)
        month = self._expand_every(month)
        # long to short, e.g. friday => fri
        weekday = self._convert_weekdays(weekday)
        # month to number, e.g. january = 1
        month = self._convert_months(month)
        # get a cron spec
        self.sched = crontab(minute=minute,
                             hour=hour,
                             day_of_month=monthday,
                             day_of_week=weekday,
                             month_of_year=month)
        # make sure the spec can be processed by croniter
        if not croniter.is_valid(self.cron):
            raise ValueError("{cronspec} is not a valid schedule")
github PrefectHQ / prefect / src / prefect / schedules / clocks.py View on Github external
def __init__(
        self, cron: str, start_date: datetime = None, end_date: datetime = None
    ):
        # build cron object to check the cron string - will raise an error if it's invalid
        if not croniter.is_valid(cron):
            raise ValueError("Invalid cron string: {}".format(cron))
        self.cron = cron
        super().__init__(start_date=start_date, end_date=end_date)