Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4bd9933a87 | ||
|
|
5c5e97faae | ||
|
|
dd7f0b5df7 | ||
|
|
5032906d91 |
@@ -5,9 +5,6 @@ import tortoise.validators
|
|||||||
|
|
||||||
from app.models.base import AbstractModel
|
from app.models.base import AbstractModel
|
||||||
|
|
||||||
# https://stackoverflow.com/a/57639657
|
|
||||||
CRONTAB_REGEX = r"^(@(annually|yearly|monthly|weekly|daily|hourly|reboot))|(@every (\d+(ns|us|µs|ms|s|m|h))+)|((((\d+,)+\d+|(\d+(\/|-)\d+)|\d+|\*) ?){5,7})$"
|
|
||||||
|
|
||||||
|
|
||||||
class Task(AbstractModel):
|
class Task(AbstractModel):
|
||||||
list_name = tortoise.fields.CharField(max_length=128, db_index=True, null=False)
|
list_name = tortoise.fields.CharField(max_length=128, db_index=True, null=False)
|
||||||
@@ -15,7 +12,6 @@ class Task(AbstractModel):
|
|||||||
reset_cron = tortoise.fields.CharField(
|
reset_cron = tortoise.fields.CharField(
|
||||||
max_length=64,
|
max_length=64,
|
||||||
null=True,
|
null=True,
|
||||||
validators=[tortoise.validators.RegexValidator(CRONTAB_REGEX, 0)],
|
|
||||||
)
|
)
|
||||||
check_date = tortoise.fields.DatetimeField(null=True)
|
check_date = tortoise.fields.DatetimeField(null=True)
|
||||||
previous_check_date = tortoise.fields.DatetimeField(null=True)
|
previous_check_date = tortoise.fields.DatetimeField(null=True)
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "tout-doux",
|
"name": "tout-doux",
|
||||||
"version": "1.3.0",
|
"version": "1.4.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "tout-doux"
|
name = "tout-doux"
|
||||||
version = "1.3.0"
|
version = "1.4.0"
|
||||||
description = ""
|
description = ""
|
||||||
requires-python = ">=3.14"
|
requires-python = ">=3.14"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
{
|
{
|
||||||
"cron": {
|
"cron": {
|
||||||
"type": {
|
"type": {
|
||||||
"one_time": "One time",
|
"manual": "Manual",
|
||||||
"every_day": "Every day",
|
"every_day": "Every day",
|
||||||
"every_week": "Every week",
|
"every_week": "Every week",
|
||||||
"every_month": "Every month",
|
"every_month": "Every month",
|
||||||
"every_year": "Every year",
|
"every_year": "Every year",
|
||||||
"specific": "Specific"
|
"custom": "Custom (crontab)",
|
||||||
|
"one_time": "One time (then delete)"
|
||||||
},
|
},
|
||||||
"week": [
|
"week": [
|
||||||
"Monday",
|
"Monday",
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
{
|
{
|
||||||
"cron": {
|
"cron": {
|
||||||
"type": {
|
"type": {
|
||||||
"one_time": "Une seule fois",
|
"manual": "Manuel",
|
||||||
"every_day": "Tous les jours",
|
"every_day": "Tous les jours",
|
||||||
"every_week": "Toutes les semaines",
|
"every_week": "Toutes les semaines",
|
||||||
"every_month": "Tous les mois",
|
"every_month": "Tous les mois",
|
||||||
"every_year": "Tous les ans",
|
"every_year": "Tous les ans",
|
||||||
"specific": "Spécifique"
|
"custom": "Personnalisé (crontab)",
|
||||||
|
"one_time": "Une seule fois (puis suppression)"
|
||||||
},
|
},
|
||||||
"week": [
|
"week": [
|
||||||
"Lundi",
|
"Lundi",
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ const rawCron = ref<string>(DEFAULT_CRON);
|
|||||||
const valid = ref<boolean>(true);
|
const valid = ref<boolean>(true);
|
||||||
const props = defineProps<{ editMode: boolean }>();
|
const props = defineProps<{ editMode: boolean }>();
|
||||||
|
|
||||||
const cronType = ref<CronType>(CronType.ONE_TIME);
|
const cronType = ref<CronType>(CronType.MANUAL);
|
||||||
const cronValue = ref<number>(0);
|
const cronValue = ref<number>(0);
|
||||||
|
|
||||||
function onCronChanged() {
|
function onCronChanged() {
|
||||||
@@ -34,7 +34,7 @@ function onChangeCronType() {
|
|||||||
case CronType.EVERY_YEAR:
|
case CronType.EVERY_YEAR:
|
||||||
cronValue.value = 1;
|
cronValue.value = 1;
|
||||||
break;
|
break;
|
||||||
case CronType.SPECIFIC:
|
case CronType.CUSTOM:
|
||||||
cron.value ??= DEFAULT_CRON;
|
cron.value ??= DEFAULT_CRON;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -64,8 +64,8 @@ watch(cron, () => {
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex gap-2">
|
<div class="flex gap-2">
|
||||||
<select v-model="cronType" class="select flex-1" @change="onChangeCronType">
|
<select v-model="cronType" class="select flex-1" @change="onChangeCronType">
|
||||||
<option :value="CronType.ONE_TIME">
|
<option :value="CronType.MANUAL">
|
||||||
{{ $t("cron.type.one_time") }}
|
{{ $t("cron.type.manual") }}
|
||||||
</option>
|
</option>
|
||||||
<option :value="CronType.EVERY_DAY">
|
<option :value="CronType.EVERY_DAY">
|
||||||
{{ $t("cron.type.every_day") }}
|
{{ $t("cron.type.every_day") }}
|
||||||
@@ -79,8 +79,11 @@ watch(cron, () => {
|
|||||||
<option :value="CronType.EVERY_YEAR">
|
<option :value="CronType.EVERY_YEAR">
|
||||||
{{ $t("cron.type.every_year") }}
|
{{ $t("cron.type.every_year") }}
|
||||||
</option>
|
</option>
|
||||||
<option :value="CronType.SPECIFIC">
|
<option :value="CronType.CUSTOM">
|
||||||
{{ $t("cron.type.specific") }}
|
{{ $t("cron.type.custom") }}
|
||||||
|
</option>
|
||||||
|
<option :value="CronType.ONE_TIME">
|
||||||
|
{{ $t("cron.type.one_time") }}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<select
|
<select
|
||||||
@@ -149,7 +152,7 @@ watch(cron, () => {
|
|||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<input
|
<input
|
||||||
v-if="cronType === CronType.SPECIFIC"
|
v-if="cronType === CronType.CUSTOM"
|
||||||
v-model="rawCron"
|
v-model="rawCron"
|
||||||
type="text"
|
type="text"
|
||||||
class="input font-mono flex-1"
|
class="input font-mono flex-1"
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import { isTemporary, taskCompleted, taskNextReset } from "@/lib/tasks";
|
|||||||
import { relativeTime } from "@/lib/dates";
|
import { relativeTime } from "@/lib/dates";
|
||||||
import { useAlertStore } from "@/stores/alerts";
|
import { useAlertStore } from "@/stores/alerts";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
|
import { isOneTime } from "@/lib/cron";
|
||||||
|
|
||||||
const emit =
|
const emit =
|
||||||
defineEmits<(e: "clone" | "delete" | "updated", task: Task) => void>();
|
defineEmits<(e: "clone" | "delete" | "updated", task: Task) => void>();
|
||||||
@@ -75,6 +76,9 @@ function onSave() {
|
|||||||
function onCheck() {
|
function onCheck() {
|
||||||
if (!isTemporary(task.value)) {
|
if (!isTemporary(task.value)) {
|
||||||
if (!checked.value) {
|
if (!checked.value) {
|
||||||
|
if (isOneTime(task.value.reset_cron)) {
|
||||||
|
emit("delete", task.value);
|
||||||
|
} else {
|
||||||
const data = {
|
const data = {
|
||||||
check_date: new Date().toISOString(),
|
check_date: new Date().toISOString(),
|
||||||
previous_check_date: task.value.check_date?.toISOString(),
|
previous_check_date: task.value.check_date?.toISOString(),
|
||||||
@@ -89,6 +93,7 @@ function onCheck() {
|
|||||||
.catch(() => {
|
.catch(() => {
|
||||||
alertError(i18n.t("alerts.task_update_error"));
|
alertError(i18n.t("alerts.task_update_error"));
|
||||||
});
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const data = {
|
const data = {
|
||||||
check_date: null,
|
check_date: null,
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
export enum CronType {
|
export enum CronType {
|
||||||
ONE_TIME,
|
MANUAL,
|
||||||
EVERY_DAY,
|
EVERY_DAY,
|
||||||
EVERY_WEEK,
|
EVERY_WEEK,
|
||||||
EVERY_MONTH,
|
EVERY_MONTH,
|
||||||
EVERY_YEAR,
|
EVERY_YEAR,
|
||||||
SPECIFIC,
|
CUSTOM,
|
||||||
|
ONE_TIME,
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum SortType {
|
export enum SortType {
|
||||||
|
|||||||
@@ -1,12 +1,19 @@
|
|||||||
import { CronType } from "@/enums";
|
import { CronType } from "@/enums";
|
||||||
import { CronExpressionParser } from "cron-parser";
|
import { CronExpressionParser } from "cron-parser";
|
||||||
|
|
||||||
|
const ONE_TIME_VALUE = "@one-time";
|
||||||
|
|
||||||
export function parseCron(cron: string | null): {
|
export function parseCron(cron: string | null): {
|
||||||
type: CronType;
|
type: CronType;
|
||||||
value: number;
|
value: number;
|
||||||
} {
|
} {
|
||||||
let value: RegExpMatchArray | null;
|
let value: RegExpMatchArray | null;
|
||||||
if (cron === null) {
|
if (cron === null) {
|
||||||
|
return {
|
||||||
|
type: CronType.MANUAL,
|
||||||
|
value: 0,
|
||||||
|
};
|
||||||
|
} else if (cron === ONE_TIME_VALUE) {
|
||||||
return {
|
return {
|
||||||
type: CronType.ONE_TIME,
|
type: CronType.ONE_TIME,
|
||||||
value: 0,
|
value: 0,
|
||||||
@@ -33,7 +40,7 @@ export function parseCron(cron: string | null): {
|
|||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
type: CronType.SPECIFIC,
|
type: CronType.CUSTOM,
|
||||||
value: 0,
|
value: 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -45,6 +52,8 @@ export function getCron(
|
|||||||
fallback: string,
|
fallback: string,
|
||||||
): string | null {
|
): string | null {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case CronType.ONE_TIME:
|
||||||
|
return ONE_TIME_VALUE;
|
||||||
case CronType.EVERY_DAY:
|
case CronType.EVERY_DAY:
|
||||||
return `0 ${value.toFixed(0)} * * *`;
|
return `0 ${value.toFixed(0)} * * *`;
|
||||||
case CronType.EVERY_WEEK:
|
case CronType.EVERY_WEEK:
|
||||||
@@ -53,7 +62,7 @@ export function getCron(
|
|||||||
return `0 0 ${value.toFixed(0)} * *`;
|
return `0 0 ${value.toFixed(0)} * *`;
|
||||||
case CronType.EVERY_YEAR:
|
case CronType.EVERY_YEAR:
|
||||||
return `0 0 1 ${value.toFixed(0)} *`;
|
return `0 0 1 ${value.toFixed(0)} *`;
|
||||||
case CronType.SPECIFIC:
|
case CronType.CUSTOM:
|
||||||
if (validCron(fallback)) {
|
if (validCron(fallback)) {
|
||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
@@ -62,6 +71,10 @@ export function getCron(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isOneTime(cron: string | null): boolean {
|
||||||
|
return cron === ONE_TIME_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
export function validCron(cron: string): boolean {
|
export function validCron(cron: string): boolean {
|
||||||
try {
|
try {
|
||||||
CronExpressionParser.parse(cron);
|
CronExpressionParser.parse(cron);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { SortType } from "@/enums";
|
import { SortType } from "@/enums";
|
||||||
import type { RawTask, Task, TaskCreateData } from "@/types";
|
import type { RawTask, Task, TaskCreateData } from "@/types";
|
||||||
import { CronExpressionParser } from "cron-parser";
|
import { CronExpressionParser } from "cron-parser";
|
||||||
|
import { isOneTime } from "@/lib/cron";
|
||||||
|
|
||||||
const TEMPORARY_ID = "tmp";
|
const TEMPORARY_ID = "tmp";
|
||||||
|
|
||||||
@@ -27,7 +28,7 @@ export function newTemporaryTask(data: TaskCreateData): Task {
|
|||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
check_date: null,
|
check_date: null,
|
||||||
previous_check_date: null,
|
previous_check_date: null,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isTemporary(task: Task): boolean {
|
export function isTemporary(task: Task): boolean {
|
||||||
@@ -35,7 +36,11 @@ export function isTemporary(task: Task): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function taskNextReset(task: Task): Date | null {
|
export function taskNextReset(task: Task): Date | null {
|
||||||
if (task.check_date === null || task.reset_cron === null) {
|
if (
|
||||||
|
task.check_date === null ||
|
||||||
|
task.reset_cron === null ||
|
||||||
|
isOneTime(task.reset_cron)
|
||||||
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -323,7 +323,7 @@ asyncpg = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tout-doux"
|
name = "tout-doux"
|
||||||
version = "1.3.0"
|
version = "1.4.0"
|
||||||
source = { editable = "." }
|
source = { editable = "." }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "flask", extra = ["async"] },
|
{ name = "flask", extra = ["async"] },
|
||||||
|
|||||||
Reference in New Issue
Block a user