CronJobs.constants.tsx 2.1 KB

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