@coreframe/jobs 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -6
- package/dist/dashboard/api.d.ts +2 -2
- package/dist/dashboard/index.d.ts +5 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/dashboard/page.js +1 -1
- package/dist/dashboard-ui/outcome-icon.js +1 -0
- package/dist/dashboard-ui/refresh-button.js +1 -0
- package/dist/dashboard-ui/value-tooltip.js +1 -0
- package/dist/development-history.d.ts +1 -1
- package/dist/scheduled-dashboard/index.d.ts +4 -2
- package/dist/scheduled-dashboard/index.js +1 -1
- package/dist/scheduled-dashboard/page.d.ts +9 -2
- package/dist/scheduled-dashboard/page.js +1 -1
- package/dist/scheduled-dashboard/trigger-icon.js +1 -0
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -95,8 +95,8 @@ Only explicit fields and the fixed safe summary reach the projection, even with
|
|
|
95
95
|
The generated template enables the Jobs page at `/__dashboard/jobs`. Its app-owned
|
|
96
96
|
`GET /api/jobs` endpoint checks a current durable session and active admin role, selects the
|
|
97
97
|
current deployment environment, and returns a private, non-cacheable snapshot. The page uses
|
|
98
|
-
the typed app client
|
|
99
|
-
|
|
98
|
+
the typed app client and passes its session to the shared Jobs page. During development, the page
|
|
99
|
+
also queries the local startup job plugin. Each job has one row with an icon for each trigger.
|
|
100
100
|
|
|
101
101
|
For another app, register `scheduledJobs({ pageModule: "./scheduled-jobs.tsx" })` from
|
|
102
102
|
`@coreframe/jobs/scheduled-dashboard` and supply an app-owned page wrapper. Render the default
|
|
@@ -104,13 +104,15 @@ component from `@coreframe/jobs/scheduled-dashboard/page` with
|
|
|
104
104
|
`loadSnapshot(signal): Promise<ScheduledJobsSnapshot>`, backed by an equivalently protected
|
|
105
105
|
app API. The schema/type is available from `@coreframe/jobs/scheduled-dashboard/api`.
|
|
106
106
|
|
|
107
|
-
The page is read-only.
|
|
108
|
-
|
|
109
|
-
operation, omit `history` and the plugin; preserve previously applied migrations.
|
|
107
|
+
The page is read-only. Cron status comes from retained observations, and local startup status
|
|
108
|
+
includes cooldown and lease information. Consult Worker logs to investigate cron failures.
|
|
110
109
|
|
|
111
110
|
## Development job history
|
|
112
111
|
|
|
113
|
-
The template
|
|
112
|
+
The template uses `devJobs({ jobsPageModule })` to mount its combined Jobs page locally at
|
|
113
|
+
`/__dashboard/jobs`. In that wrapper, pass `includeLocalStartup` to the shared Jobs page, and set
|
|
114
|
+
`environments: ["deployed"]` on the `scheduledJobs` registration. A project that only needs local
|
|
115
|
+
startup jobs can register the standalone Dev jobs page at `/__dashboard/dev-jobs`:
|
|
114
116
|
|
|
115
117
|
```ts
|
|
116
118
|
import { defineConfig } from "@coreframe/dashboard/config"
|
package/dist/dashboard/api.d.ts
CHANGED
|
@@ -7,10 +7,10 @@ declare const job: z.ZodObject<{
|
|
|
7
7
|
lastSucceededAt: z.ZodNullable<z.ZodString>;
|
|
8
8
|
nextEligibleAt: z.ZodNullable<z.ZodString>;
|
|
9
9
|
eligibility: z.ZodEnum<{
|
|
10
|
-
unknown: "unknown";
|
|
11
10
|
cooldown: "cooldown";
|
|
12
11
|
due: "due";
|
|
13
12
|
"never-run": "never-run";
|
|
13
|
+
unknown: "unknown";
|
|
14
14
|
}>;
|
|
15
15
|
lease: z.ZodEnum<{
|
|
16
16
|
active: "active";
|
|
@@ -30,9 +30,9 @@ declare const attempt: z.ZodObject<{
|
|
|
30
30
|
finishedAt: z.ZodNullable<z.ZodString>;
|
|
31
31
|
outcome: z.ZodEnum<{
|
|
32
32
|
unknown: "unknown";
|
|
33
|
+
running: "running";
|
|
33
34
|
succeeded: "succeeded";
|
|
34
35
|
failed: "failed";
|
|
35
|
-
running: "running";
|
|
36
36
|
skipped: "skipped";
|
|
37
37
|
}>;
|
|
38
38
|
skipReason: z.ZodNullable<z.ZodEnum<{
|
|
@@ -2,6 +2,10 @@ import { DashboardPlugin } from "@coreframe/dashboard/config";
|
|
|
2
2
|
|
|
3
3
|
//#region src/dashboard/index.d.ts
|
|
4
4
|
/** Read-only project-local job status and attempt history. */
|
|
5
|
-
declare function devJobs(
|
|
5
|
+
declare function devJobs({
|
|
6
|
+
jobsPageModule
|
|
7
|
+
}?: {
|
|
8
|
+
jobsPageModule?: string;
|
|
9
|
+
}): DashboardPlugin;
|
|
6
10
|
//#endregion
|
|
7
11
|
export { devJobs };
|
package/dist/dashboard/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{api as e}from"./api.js";import{definePlugin as t}from"@coreframe/dashboard/config";function n(){return t({id:`dev-jobs`,navigation:{path
|
|
1
|
+
import{api as e}from"./api.js";import{definePlugin as t}from"@coreframe/dashboard/config";function n({jobsPageModule:n}={}){return t({id:`dev-jobs`,navigation:{path:n?`jobs`:`dev-jobs`,title:n?`Jobs`:`Dev jobs`,icon:`list-check`,environments:[`local`]},pageModule:n??`@coreframe/jobs/dashboard/page`,api:e},{apiModule:`@coreframe/jobs/dashboard/api`,localImplementationModule:`@coreframe/jobs/dashboard/local`})}export{n as devJobs};
|
package/dist/dashboard/page.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{api as e}from"./api.js";import{
|
|
1
|
+
import{api as e}from"./api.js";import{OutcomeIcon as t}from"../dashboard-ui/outcome-icon.js";import{RefreshButton as n}from"../dashboard-ui/refresh-button.js";import{createClient as r}from"@coreframe/dashboard/api";import{Field as i,Page as a,PageHeader as o,Section as s,Tabs as c}from"@coreframe/dashboard/ui";import{useQuery as l}from"@tanstack/react-query";import{useState as u}from"react";import{Fragment as d,jsx as f,jsxs as p}from"react/jsx-runtime";const m={padding:`10px 14px`,textAlign:`left`,borderBottom:`1px solid var(--colors-border, #8884)`,verticalAlign:`top`},h=e=>e?new Date(e).toLocaleString():`—`;function g(){let[d,g]=u(`jobs`),[y,b]=u(``),[x,S]=u(``),C=l({queryKey:[`dashboard`,`dev-jobs`,`snapshot`],queryFn:({signal:t})=>r(e).queries.snapshot({signal:t}),refetchInterval:3e3,retry:!1}),w=C.data,T=w?.attempts.filter(e=>(!y||e.jobId===y)&&(!x||e.outcome===x))??[],E=[...new Set([...w?.jobs.map(e=>e.id)??[],...w?.attempts.map(e=>e.jobId)??[]])].sort();return p(a,{children:[p(o,{style:{marginBottom:`0.75rem`},children:[p(`div`,{children:[f(`h1`,{style:{fontSize:`1.25rem`},children:`Dev jobs`}),f(`p`,{children:`Local startup jobs and their recent attempts.`})]}),f(n,{busy:C.isFetching,onRefresh:()=>void C.refetch()})]}),p(s,{"aria-label":`Dev jobs activity`,style:{paddingBlockStart:`0.5rem`},children:[C.isPending&&f(`p`,{role:`status`,children:`Loading development jobs…`}),C.isError&&p(`p`,{role:`alert`,children:[`Could not refresh development jobs. Check the local database and migrations, then refresh.`,w?` Showing the last successful snapshot.`:``]}),w?.notice&&f(`p`,{role:`status`,children:w.notice}),w&&p(c,{value:d,onValueChange:g,children:[p(c.List,{children:[p(c.Trigger,{value:`jobs`,children:[`Jobs (`,w.jobs.length,`)`]}),p(c.Trigger,{value:`history`,children:[`History (`,w.attempts.length,`)`]})]}),f(c.Panel,{value:`jobs`,children:w.jobs.length===0?f(`p`,{children:`No development jobs are configured.`}):f(v,{headings:[`Job`,`Latest outcome`,`Scheduling`,`Last success`,`Next eligible`,`Lease`],children:w.jobs.map(e=>p(`tr`,{children:[p(`td`,{style:m,children:[f(`code`,{children:e.id}),e.registration===`orphaned`&&f(`p`,{children:`No longer configured`})]}),f(`td`,{style:m,children:f(t,{value:w.attempts.find(t=>t.jobId===e.id)?.outcome})}),f(`td`,{style:m,children:e.eligibility===`cooldown`?`Cooling down`:e.eligibility===`never-run`?`No recorded success`:e.eligibility}),f(`td`,{style:m,children:h(e.lastSucceededAt)}),f(`td`,{style:m,children:h(e.nextEligibleAt)}),p(`td`,{style:m,children:[e.lease,e.leaseUntil&&p(`p`,{children:[`Until `,h(e.leaseUntil)]})]})]},e.id))})}),p(c.Panel,{value:`history`,children:[p(`div`,{style:{display:`flex`,gap:16,flexWrap:`wrap`,marginBottom:16},children:[f(i,{label:`Job`,children:p(`select`,{value:y,onChange:e=>b(e.target.value),children:[f(`option`,{value:``,children:`All jobs`}),E.map(e=>f(`option`,{children:e},e))]})}),f(i,{label:`Outcome`,children:p(`select`,{value:x,onChange:e=>S(e.target.value),children:[f(`option`,{value:``,children:`All outcomes`}),[`running`,`succeeded`,`failed`,`skipped`,`unknown`].map(e=>f(`option`,{children:e},e))]})})]}),f(`p`,{children:`Up to 1,000 attempts from the last 30 days. History is best effort; missing records do not prove a job never ran. Unknown means the lease expired without a recorded result.`}),T.length===0?f(`p`,{children:w.historyAvailable?`No recorded attempts match these filters.`:`Attempt history is unavailable.`}):f(v,{headings:[`Job`,`Started`,`Duration`,`Outcome`,`Details`],children:T.map(e=>f(_,{attempt:e},e.id))})]})]})]})]})}function _({attempt:e}){return p(`tr`,{children:[f(`td`,{style:m,children:f(`code`,{children:e.jobId})}),f(`td`,{style:m,children:h(e.startedAt)}),f(`td`,{style:m,children:e.durationMs===null?`—`:`${(e.durationMs/1e3).toFixed(2)}s`}),f(`td`,{style:m,children:f(t,{value:e.outcome})}),f(`td`,{style:m,children:p(`details`,{children:[f(`summary`,{children:`View attempt`}),p(`dl`,{children:[f(`dt`,{children:`Attempt`}),f(`dd`,{children:f(`code`,{children:e.id})}),f(`dt`,{children:`Started`}),f(`dd`,{children:h(e.startedAt)}),f(`dt`,{children:`Finished`}),f(`dd`,{children:h(e.finishedAt)}),e.skipReason&&p(d,{children:[f(`dt`,{children:`Skipped because`}),f(`dd`,{children:e.skipReason===`cooldown`?`Cooldown has not elapsed`:`Another attempt holds the lease`})]}),e.errorSummary&&p(d,{children:[f(`dt`,{children:`Error`}),f(`dd`,{children:e.errorSummary})]})]})]})})]})}function v({headings:e,children:t}){return f(`div`,{style:{overflowX:`auto`},children:p(`table`,{style:{width:`100%`,borderCollapse:`collapse`,fontVariantNumeric:`tabular-nums`},children:[f(`thead`,{children:f(`tr`,{children:e.map(e=>f(`th`,{style:m,scope:`col`,children:e},e))})}),f(`tbody`,{children:t})]})})}export{g as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ValueTooltip as e}from"./value-tooltip.js";import{jsx as t}from"react/jsx-runtime";const n={succeeded:{label:`Succeeded`,color:`var(--colors-dashboard-success, #15803d)`,path:`M22 12a10 10 0 1 1-20 0 10 10 0 0 1 20 0ZM8 12l3 3 5-6`},failed:{label:`Failed`,color:`var(--colors-dashboard-danger, #dc2626)`,path:`M22 12a10 10 0 1 1-20 0 10 10 0 0 1 20 0ZM9 9l6 6m0-6-6 6`},running:{label:`Running`,color:`var(--colors-dashboard-info, #2563eb)`,path:`M12 3a9 9 0 1 1-9 9`},skipped:{label:`Skipped`,color:`var(--colors-dashboard-muted, #68717d)`,path:`m5 5 11 7-11 7V5Zm14 0v14`},unknown:{label:`Unknown`,color:`var(--colors-dashboard-warning, #b45309)`,path:`M22 12a10 10 0 1 1-20 0 10 10 0 0 1 20 0ZM9 9a3 3 0 1 1 4.8 2.4c-1.2.9-1.8 1.6-1.8 2.6m0 3h.01`},missing:{label:`No recorded attempts`,color:`var(--colors-dashboard-muted, #68717d)`,path:`M7 12h10`}};function r({value:r=`missing`}){let{label:i,color:a,path:o}=n[r];return t(e,{label:i,detail:i,style:{color:a,display:`inline-grid`,placeItems:`center`,width:28,height:28},children:t(`svg`,{"aria-hidden":`true`,width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,strokeLinecap:`round`,strokeLinejoin:`round`,children:t(`path`,{d:o})})})}export{r as OutcomeIcon};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ValueTooltip as e}from"./value-tooltip.js";import{jsx as t}from"react/jsx-runtime";function n({busy:n,onRefresh:r}){return t(e,{label:`Refresh`,detail:`Refresh`,isPending:n,onPress:({target:e})=>{globalThis.matchMedia(`(prefers-reduced-motion: reduce)`).matches||e.querySelector(`svg`)?.animate([{scale:`0.88`},{scale:`1.1`,offset:.55},{scale:`1`}],{duration:240,easing:`ease-out`}),r()},style:({isHovered:e,isPending:t})=>({display:`inline-grid`,placeItems:`center`,width:36,height:36,borderRadius:8,backgroundColor:e?`color-mix(in srgb, var(--colors-dashboard-ink, #1f2937) 7%, transparent)`:`transparent`,transition:`background-color 150ms ease, opacity 150ms ease`,opacity:t?.55:1}),children:t(`svg`,{"aria-hidden":`true`,width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,strokeLinecap:`round`,strokeLinejoin:`round`,children:t(`path`,{d:`M20 10a8 8 0 0 0-14-3L4 9m0-5v5h5m-5 5a8 8 0 0 0 14 3l2-2m0 5v-5h-5`})})})}export{n as RefreshButton};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Button as e,Tooltip as t,TooltipTrigger as n}from"react-aria-components";import{jsx as r,jsxs as i}from"react/jsx-runtime";function a({children:a,label:o,detail:s,isPending:c,onPress:l,style:u}){return i(n,{delay:200,children:[r(e,{"aria-label":o,isPending:c,onPress:l,style:e=>({padding:0,border:0,borderRadius:4,background:`transparent`,color:`inherit`,font:`inherit`,...typeof u==`function`?u(e):u}),children:a}),r(t,{offset:6,style:{zIndex:50,padding:`5px 8px`,borderRadius:4,background:`var(--colors-dashboard-ink, #242424)`,color:`var(--colors-dashboard-panel, #fff)`,fontSize:`0.8rem`},children:s})]})}export{a as ValueTooltip};
|
|
@@ -19,6 +19,6 @@ type DevelopmentJobHistoryStore = {
|
|
|
19
19
|
declare const developmentJobHistoryRetentionDays = 30;
|
|
20
20
|
declare const developmentJobHistoryLimit = 1000;
|
|
21
21
|
/** An unfinished attempt is not proof of failure, even after its lease expires. */
|
|
22
|
-
declare function developmentJobAttemptOutcome(attempt: DevelopmentJobAttempt, now: Date): "unknown" | "
|
|
22
|
+
declare function developmentJobAttemptOutcome(attempt: DevelopmentJobAttempt, now: Date): "unknown" | "running" | "succeeded" | "failed" | "skipped";
|
|
23
23
|
//#endregion
|
|
24
24
|
export { DevelopmentJobAttempt, DevelopmentJobHistoryStore, developmentJobAttemptOutcome, developmentJobHistoryLimit, developmentJobHistoryRetentionDays };
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { DashboardPlugin } from "@coreframe/dashboard/config";
|
|
1
|
+
import { DashboardEnvironment, DashboardPlugin } from "@coreframe/dashboard/config";
|
|
2
2
|
|
|
3
3
|
//#region src/scheduled-dashboard/index.d.ts
|
|
4
4
|
/** A read-only page backed by the hosting app's authenticated history API. */
|
|
5
5
|
declare function scheduledJobs({
|
|
6
|
-
pageModule
|
|
6
|
+
pageModule,
|
|
7
|
+
environments
|
|
7
8
|
}: {
|
|
8
9
|
pageModule: string;
|
|
10
|
+
environments?: readonly DashboardEnvironment[];
|
|
9
11
|
}): DashboardPlugin;
|
|
10
12
|
//#endregion
|
|
11
13
|
export { scheduledJobs };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{definePlugin as e}from"@coreframe/dashboard/config";function t({pageModule:t}){return e({id:`scheduled-jobs`,navigation:{path:`jobs`,title:`Jobs`,icon:`list-check
|
|
1
|
+
import{definePlugin as e}from"@coreframe/dashboard/config";function t({pageModule:t,environments:n}){return e({id:`scheduled-jobs`,navigation:{path:`jobs`,title:`Jobs`,icon:`list-check`,environments:n},pageModule:t})}export{t as scheduledJobs};
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { ScheduledJobsSnapshot } from "./api.js";
|
|
2
|
+
import { DashboardAppSession } from "@coreframe/dashboard/app-client";
|
|
2
3
|
|
|
3
4
|
//#region src/scheduled-dashboard/page.d.ts
|
|
4
|
-
/** The app owns authorization, environment selection and the database connection. */
|
|
5
|
+
/** The app owns authorization, environment selection and the scheduled database connection. */
|
|
5
6
|
declare function ScheduledJobsPage({
|
|
6
|
-
|
|
7
|
+
cronDayOfWeekStartIndexZero,
|
|
8
|
+
includeLocalStartup,
|
|
9
|
+
loadSnapshot,
|
|
10
|
+
session
|
|
7
11
|
}: {
|
|
12
|
+
/** Set to false for schedulers that number Sunday as 1, including Cloudflare Workers. */cronDayOfWeekStartIndexZero?: boolean;
|
|
13
|
+
includeLocalStartup?: boolean;
|
|
8
14
|
loadSnapshot(signal: AbortSignal): Promise<ScheduledJobsSnapshot>;
|
|
15
|
+
session?: DashboardAppSession;
|
|
9
16
|
}): import("react").JSX.Element;
|
|
10
17
|
//#endregion
|
|
11
18
|
export { ScheduledJobsPage as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{api as e}from"../dashboard/api.js";import{ValueTooltip as t}from"../dashboard-ui/value-tooltip.js";import{OutcomeIcon as n}from"../dashboard-ui/outcome-icon.js";import{RefreshButton as r}from"../dashboard-ui/refresh-button.js";import{TriggerIcon as i,triggerLabels as a}from"./trigger-icon.js";import{createClient as o}from"@coreframe/dashboard/api";import{Field as s,Page as c,PageHeader as l,Section as u,Tabs as d}from"@coreframe/dashboard/ui";import{skipToken as f,useQuery as p}from"@tanstack/react-query";import{useEffect as m,useState as h,useSyncExternalStore as g}from"react";import{Fragment as _,jsx as v,jsxs as y}from"react/jsx-runtime";import{DashboardAppResponseError as b}from"@coreframe/dashboard/app-client";import x from"cronstrue";const S={padding:`10px 14px`,textAlign:`left`,borderBottom:`1px solid var(--colors-dashboard-border, #8884)`,verticalAlign:`top`},C={display:`flex`,gap:16,flexWrap:`wrap`,marginBottom:16},w=new Intl.DateTimeFormat(void 0,{year:`numeric`,month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`,second:`2-digit`,timeZoneName:`short`}),T=()=>()=>{},E=()=>void 0;function D({cronDayOfWeekStartIndexZero:t=!0,includeLocalStartup:n=!1,loadSnapshot:i,session:a}){let[_,x]=h(`jobs`),[S,w]=h(``),[D,A]=h(``),[j,M]=h(``),[N,I]=h(``),[L,R]=h(Date.now);m(()=>{let e=globalThis.setInterval(()=>R(Date.now()),1e3);return()=>globalThis.clearInterval(e)},[]);let z=g(a?.subscribe??T,a?.get??E,a?.get??E)?.status,B=!a||z===`authenticated`,V=p({queryKey:[`dashboard`,`scheduled-jobs`,`snapshot`],queryFn:B?({signal:e})=>i(e):f,refetchInterval:3e4,retry:!1}),H=p({queryKey:[`dashboard`,`dev-jobs`,`snapshot`],queryFn:n?({signal:t})=>o(e).queries.snapshot({signal:t}):f,refetchInterval:3e3,retry:!1}),U=V.error instanceof b&&(V.error.status===401||V.error.status===403),W=B&&!U?V.data:void 0,G=n?H.data:void 0,K=new Map;for(let e of W?.jobs??[])K.set(e.id,{id:e.id,cron:e});for(let e of G?.jobs??[])K.set(e.id,{...K.get(e.id),id:e.id,local:e});let q=[...K.values()].sort((e,t)=>e.id.localeCompare(t.id)),J=[...(G?.attempts??[]).map(e=>({trigger:`local`,record:e})),...(W?.attempts??[]).map(e=>({trigger:`cron`,record:e}))];J.sort((e,t)=>Date.parse(t.record.startedAt)-Date.parse(e.record.startedAt));let Y=new Map;for(let e of J)e.trigger===`local`&&!Y.has(e.record.jobId)&&Y.set(e.record.jobId,e.record);let X=[...new Set([...K.keys(),...J.map(({record:e})=>e.jobId)])].sort((e,t)=>e.localeCompare(t)),Z=q.filter(e=>!S||(S===`local`?e.local:e.cron)),Q=J.filter(({trigger:e,record:t})=>(!D||e===D)&&(!j||t.jobId===j)&&(!N||t.outcome===N));function $(){n&&H.refetch(),B?V.refetch():a?.refresh()}return y(c,{children:[y(l,{style:{marginBottom:`0.75rem`},children:[v(`h1`,{style:{alignSelf:`center`,fontSize:`0.875rem`},children:`Jobs`}),v(r,{busy:V.isFetching||H.isFetching||z===`checking`,onRefresh:$})]}),y(u,{"aria-label":`Jobs activity`,style:{paddingBlockStart:`0.5rem`},children:[z===`checking`&&v(`p`,{role:`status`,children:`Checking app session for cron jobs…`}),z===`unauthenticated`&&v(`p`,{role:`alert`,children:`Sign in to the app to view cron jobs.`}),z===`unknown`&&v(`p`,{role:`alert`,children:`Could not check the app session for cron jobs. Try refreshing.`}),B&&V.isPending&&v(`p`,{role:`status`,children:`Loading cron jobs…`}),B&&V.isError&&y(`p`,{role:`alert`,children:[U?`Cron jobs require current admin access.`:`Could not refresh cron jobs.`,W?` Showing the last successful snapshot.`:``]}),W?.notice&&y(`p`,{role:`status`,children:[`Cron: `,W.notice]}),n&&H.isPending&&v(`p`,{role:`status`,children:`Loading local startup jobs…`}),n&&H.isError&&y(`p`,{role:`alert`,children:[`Could not refresh local startup jobs. Check the local database and migrations.`,G?` Showing the last successful snapshot.`:``]}),G?.notice&&y(`p`,{role:`status`,children:[`Local startup: `,G.notice]}),(W||G)&&y(d,{value:_,onValueChange:x,children:[y(d.List,{children:[y(d.Trigger,{value:`jobs`,children:[`Jobs (`,q.length,`)`]}),y(d.Trigger,{value:`history`,children:[`History (`,J.length,`)`]})]}),y(d.Panel,{value:`jobs`,children:[n&&v(`div`,{style:C,children:v(O,{label:`Runs on`,value:S,onChange:w})}),Z.length?v(F,{headings:[`Job`,`Runs on`,`Latest outcome`,`Schedule`,`Last attempt`,`Last recorded success`],children:Z.map(e=>v(k,{id:e.id,local:S===`cron`?void 0:e.local,cron:S===`local`?void 0:e.cron,cronDayOfWeekStartIndexZero:t,latestLocal:Y.get(e.id),now:L},e.id))}):v(`p`,{children:`No matching jobs in the loaded sources.`})]}),y(d.Panel,{value:`history`,children:[y(`div`,{style:C,children:[v(s,{label:`Job`,children:y(`select`,{value:j,onChange:e=>M(e.target.value),children:[v(`option`,{value:``,children:`All jobs`}),X.map(e=>v(`option`,{children:e},e))]})}),n&&v(O,{label:`Trigger`,value:D,onChange:A}),v(s,{label:`Outcome`,children:y(`select`,{value:N,onChange:e=>I(e.target.value),children:[v(`option`,{value:``,children:`All outcomes`}),[`succeeded`,`failed`,`unknown`,...n?[`running`,`skipped`]:[]].map(e=>v(`option`,{children:e},e))]})})]}),v(`p`,{children:`Each source retains up to 1,000 attempts from the last 30 days. History may be incomplete. Unknown means no final outcome was recorded.`}),Q.length?v(F,{headings:[`Job`,`Trigger`,`Started`,`Duration`,`Outcome`,`Details`],children:v(`tbody`,{children:Q.map(e=>v(P,{attempt:e,now:L},`${e.trigger}:${e.record.id}`))})}):v(`p`,{children:`No matching attempts in the loaded history.`})]})]})]})]})}function O({label:e,value:t,onChange:n}){return v(s,{label:e,children:y(`select`,{value:t,onChange:e=>n(e.target.value),children:[v(`option`,{value:``,children:`All triggers`}),v(`option`,{value:`local`,children:a.local}),v(`option`,{value:`cron`,children:a.cron})]})})}function k({id:e,local:t,cron:r,cronDayOfWeekStartIndexZero:a,latestLocal:o,now:s}){let c=v(`th`,{scope:`rowgroup`,rowSpan:t&&r?2:1,style:{...S,fontWeight:`normal`},children:v(`code`,{children:e})});return y(`tbody`,{children:[t&&y(`tr`,{children:[c,v(`td`,{style:S,children:v(i,{trigger:`local`,orphaned:t.registration===`orphaned`})}),v(`td`,{style:S,children:v(n,{value:o?.outcome})}),v(`td`,{style:S,children:v(M,{job:t,now:s})}),v(`td`,{style:S,children:v(N,{value:o?.startedAt??null,now:s})}),v(`td`,{style:S,children:v(N,{value:t.lastSucceededAt,now:s})})]}),r&&y(`tr`,{children:[!t&&c,v(`td`,{style:S,children:v(i,{trigger:`cron`,orphaned:r.registration===`orphaned`})}),v(`td`,{style:S,children:v(n,{value:r.lastAttemptAt?r.latestOutcome:void 0})}),r.registration===`orphaned`?v(`td`,{style:S,children:`No longer configured`}):v(`td`,{style:{...S,padding:0},children:v(A,{expressions:r.crons,dayOfWeekStartIndexZero:a})}),v(`td`,{style:S,children:v(N,{value:r.lastAttemptAt,now:s})}),v(`td`,{style:S,children:v(N,{value:r.lastSucceededAt,now:s})})]})]})}function A({expressions:e,dayOfWeekStartIndexZero:n}){return e.length?v(t,{detail:e.map(e=>v(`div`,{children:v(`code`,{children:e})},e)),style:{display:`block`,width:`100%`,textAlign:`left`,padding:S.padding},children:e.map(e=>v(`span`,{style:{display:`block`},children:j(e,n)},e))}):v(`span`,{style:{display:`block`,padding:S.padding},children:`—`})}function j(e,t){try{return`${x.toString(e,{use24HourTimeFormat:!0,dayOfWeekStartIndexZero:t})} (UTC)`}catch{return`Schedule description unavailable`}}function M({job:e,now:t}){let n={cooldown:`Due`,due:`Due`,"never-run":`No recorded success`,unknown:`Unknown`}[e.eligibility],r=e.nextEligibleAt;return y(_,{children:[e.registration===`orphaned`?`No longer configured`:r&&Date.parse(r)>t?v(N,{value:r,now:t,context:`Eligible`}):n,e.lease===`active`&&e.leaseUntil&&y(`div`,{children:[`Lease ends `,v(N,{value:e.leaseUntil,now:t})]}),e.lease===`expired`&&v(`div`,{children:`Lease expired`})]})}function N({value:e,now:n,context:r}){let i=e===null?NaN:Date.parse(e);if(!Number.isFinite(i))return`—`;let a=i-n,o=Math.floor(Math.abs(a)/1e3),s=o>=86400?`${Math.floor(o/86400)}d`:o>=3600?`${Math.floor(o/3600)}h`:o>=60?`${Math.floor(o/60)}m`:`${o}s`,c=o===0?`now`:a>0?`in ${s}`:`${s} ago`,l=w.format(i);return v(t,{label:r&&`${r} ${c}`,detail:r?`${r} ${l}`:l,style:{whiteSpace:`nowrap`},children:v(`time`,{dateTime:new Date(i).toISOString(),children:c})})}function P({attempt:e,now:t}){let{record:r,trigger:i}=e;return y(`tr`,{children:[v(`td`,{style:S,children:v(`code`,{children:r.jobId})}),v(`td`,{style:S,children:a[i]}),v(`td`,{style:S,children:v(N,{value:r.startedAt,now:t})}),v(`td`,{style:S,children:r.durationMs===null?`—`:`${r.durationMs} ms`}),v(`td`,{style:S,children:v(n,{value:r.outcome})}),v(`td`,{style:S,children:y(`details`,{children:[v(`summary`,{children:`Attempt details`}),y(`dl`,{children:[v(`dt`,{children:`Attempt`}),v(`dd`,{children:v(`code`,{children:r.id})}),e.trigger===`cron`&&y(_,{children:[v(`dt`,{children:`Environment`}),v(`dd`,{children:e.record.environment}),v(`dt`,{children:`Cron`}),v(`dd`,{children:v(`code`,{children:e.record.cron})}),v(`dt`,{children:`Scheduled`}),v(`dd`,{children:v(N,{value:e.record.scheduledAt,now:t})})]}),v(`dt`,{children:`Finished`}),v(`dd`,{children:v(N,{value:r.finishedAt,now:t})}),e.trigger===`local`&&e.record.skipReason&&y(_,{children:[v(`dt`,{children:`Skipped because`}),v(`dd`,{children:e.record.skipReason===`cooldown`?`Cooldown has not elapsed`:`Another attempt holds the lease`})]}),r.errorSummary&&y(_,{children:[v(`dt`,{children:`Error`}),v(`dd`,{children:r.errorSummary})]})]})]})})]})}function F({children:e,headings:t}){return v(`div`,{style:{overflowX:`auto`},children:y(`table`,{style:{width:`100%`,borderCollapse:`collapse`,fontVariantNumeric:`tabular-nums`},children:[v(`thead`,{children:v(`tr`,{children:t.map(e=>v(`th`,{scope:`col`,style:S,children:e},e))})}),e]})})}export{D as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ValueTooltip as e}from"../dashboard-ui/value-tooltip.js";import{jsx as t}from"react/jsx-runtime";const n={local:`Local startup`,cron:`Cron`};function r({trigger:r,orphaned:i}){let a=n[r];return t(e,{label:a,detail:i?`${a} (no longer configured)`:a,style:{display:`inline-grid`,placeItems:`center`,width:28,height:28,opacity:i?.6:1},children:t(`svg`,{"aria-hidden":`true`,width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,strokeLinecap:`round`,strokeLinejoin:`round`,children:r===`local`?t(`path`,{d:`m5 7 5 5-5 5m8 0h6`}):t(`path`,{d:`M12 7v5l3 2m6-2a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z`})})})}export{r as TriggerIcon,n as triggerLabels};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coreframe/jobs",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Shared scheduled-job contracts and execution helpers for Coreframe apps",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -59,11 +59,13 @@
|
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@tanstack/react-query": "^5.101.2",
|
|
62
|
+
"cronstrue": "^3.41.0",
|
|
62
63
|
"react": "19.2.8",
|
|
64
|
+
"react-aria-components": "^1.22.1",
|
|
63
65
|
"zod": "4.4.3",
|
|
64
|
-
"@coreframe/
|
|
65
|
-
"@coreframe/
|
|
66
|
-
"@coreframe/db": "^0.2.
|
|
66
|
+
"@coreframe/dashboard": "^0.4.2",
|
|
67
|
+
"@coreframe/config": "^0.3.2",
|
|
68
|
+
"@coreframe/db": "^0.2.5"
|
|
67
69
|
},
|
|
68
70
|
"devDependencies": {
|
|
69
71
|
"@libsql/client": "^0.17.4",
|