-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from anexia/cron_seconds
Allow seconds in cron string settings
- Loading branch information
Showing
8 changed files
with
73 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import re | ||
|
||
from cronfield.models import CronField | ||
from django.core.exceptions import ValidationError | ||
|
||
|
||
def _validate_CRON_string(value): | ||
"""Validation routine for CRON string in TestingPlan""" | ||
|
||
if value.strip() != value: | ||
raise ValidationError("Leading nor trailing spaces are allowed") | ||
columns = value.split() | ||
if columns != value.split(" "): | ||
raise ValidationError("Use only a single space as a column separator") | ||
|
||
if len(columns) not in [5, 6]: | ||
raise ValidationError("Entry has to consist of 5 or 6 columns") | ||
|
||
pattern = r"^(\*|\d+(-\d+)?(,\d+(-\d+)?)*)(/\d+)?$" | ||
p = re.compile(pattern) | ||
for i, c in enumerate(columns): | ||
if not p.match(c): | ||
raise ValidationError("Incorrect value {} in column {}".format(c, i + 1)) | ||
|
||
|
||
class FutureTaskCronField(CronField): | ||
def validate(self, value, model_instance): | ||
super(CronField, self).validate(value, model_instance) | ||
if self.editable: # Skip validation for non-editable fields. | ||
_validate_CRON_string(value) | ||
|
||
def __init__(self, *args, **kwargs): | ||
kwargs["default"] = "* * * * * *" | ||
kwargs["help_text"] = "Minute Hour Day Month Weekday Second" | ||
super().__init__(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
django_future_tasks/migrations/0007_alter_periodicfuturetask_cron_string.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 4.2.14 on 2024-07-22 11:43 | ||
|
||
from django.db import migrations | ||
|
||
import django_future_tasks.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("django_future_tasks", "0006_periodicfuturetask_end_time"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="periodicfuturetask", | ||
name="cron_string", | ||
field=django_future_tasks.fields.FutureTaskCronField( | ||
default="* * * * * *", | ||
help_text="Minute Hour Day Month Weekday Second", | ||
max_length=100, | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters