CronJobs.constants.tsx69 lines · main
1import { EdgeFunctions, RESTApi, SqlEditor } from 'icons'
2import { ScrollText } from 'lucide-react'
3
4const cronField = /(\*|(\d+|\*\/\d+)|\d+\/\d+|\d+-\d+|\d+(,\d+)*)/
5const cronDayOfMonth = /(\*|\$|(\d+|\*\/\d+)|\d+\/\d+|\d+-\d+|\d+(,\d+)*)/
6export const cronPattern = new RegExp(
7 `^${cronField.source}\\s+${cronField.source}\\s+${cronDayOfMonth.source}\\s+${cronField.source}\\s+${cronField.source}$`
8)
9
10// detect seconds like "10 seconds" or normal cron syntax like "*/5 * * * *"
11export const secondsPattern = /^\d+\s+seconds*$/
12
13export const CRONJOB_TYPES = [
14 'http_request',
15 'edge_function',
16 'sql_function',
17 'sql_snippet',
18] as const
19
20export const CRONJOB_DEFINITIONS = [
21 {
22 value: 'sql_snippet',
23 icon: <SqlEditor strokeWidth={1} />,
24 label: 'SQL Snippet',
25 description: 'Write a SQL snippet to run.',
26 },
27 {
28 value: 'sql_function',
29 icon: <ScrollText strokeWidth={1} />,
30 label: 'Database function',
31 description: 'Choose a database function to run.',
32 },
33
34 {
35 value: 'http_request',
36 icon: <RESTApi strokeWidth={1} />,
37 label: 'HTTP Request',
38 description: 'Send an HTTP request to any URL.',
39 },
40 {
41 value: 'edge_function',
42 icon: <EdgeFunctions strokeWidth={1} />,
43 label: 'Briven Edge Function',
44 description: 'Choose a Briven edge function to run.',
45 },
46]
47
48export type HTTPHeader = { name: string; value: string }
49
50export type HTTPParameter = { name: string; value: string }
51
52type CronTableColumn = {
53 id: string
54 name: string
55 width?: number
56 minWidth?: number
57 maxWidth?: number
58 resizable?: boolean
59}
60
61export const CRON_TABLE_COLUMNS: CronTableColumn[] = [
62 { id: 'jobname', name: 'Name', minWidth: 160, width: 200, resizable: true },
63 { id: 'schedule', name: 'Schedule', width: 100, resizable: true },
64 { id: 'latest_run', name: 'Last run', width: 265, resizable: true },
65 { id: 'next_run', name: 'Next run', minWidth: 180, resizable: true },
66 { id: 'command', name: 'Command', minWidth: 320, resizable: true },
67 { id: 'active', name: 'Active', width: 70, minWidth: 70, maxWidth: 70, resizable: false },
68 { id: 'actions', name: '', minWidth: 75, width: 75, resizable: false },
69]