11import type { Meta , StoryObj } from '@storybook/vue3-vite'
22
3- import type { TaskStatus } from '@/schemas/apiSchema '
3+ import type { JobListItem } from '@/platform/remote/comfyui/jobs/types/jobTypes '
44import { useExecutionStore } from '@/stores/executionStore'
55import { TaskItemImpl , useQueueStore } from '@/stores/queueStore'
66
@@ -37,91 +37,88 @@ function resetStores() {
3737 exec . nodeProgressStatesByPrompt = { }
3838}
3939
40- function makePendingTask (
40+ function makeTask (
4141 id : string ,
42- index : number ,
43- createTimeMs ?: number
42+ priority : number ,
43+ overrides : Omit < Partial < JobListItem > , 'id' | 'priority' > &
44+ Pick < JobListItem , 'status' | 'create_time' | 'update_time' >
4445) : TaskItemImpl {
45- const extraData = {
46- client_id : 'c1' ,
47- ...( typeof createTimeMs === 'number' ? { create_time : createTimeMs } : { } )
46+ const job : JobListItem = {
47+ id,
48+ priority,
49+ last_state_update : null ,
50+ ...overrides
4851 }
49- return new TaskItemImpl ( 'Pending' , [ index , id , { } , extraData , [ ] ] )
52+ return new TaskItemImpl ( job )
53+ }
54+
55+ function makePendingTask (
56+ id : string ,
57+ priority : number ,
58+ createTimeMs : number
59+ ) : TaskItemImpl {
60+ return makeTask ( id , priority , {
61+ status : 'pending' ,
62+ create_time : createTimeMs ,
63+ update_time : createTimeMs
64+ } )
5065}
5166
5267function makeRunningTask (
5368 id : string ,
54- index : number ,
55- createTimeMs ? : number
69+ priority : number ,
70+ createTimeMs : number
5671) : TaskItemImpl {
57- const extraData = {
58- client_id : 'c1 ' ,
59- ... ( typeof createTimeMs === 'number' ? { create_time : createTimeMs } : { } )
60- }
61- return new TaskItemImpl ( 'Running' , [ index , id , { } , extraData , [ ] ] )
72+ return makeTask ( id , priority , {
73+ status : 'in_progress ' ,
74+ create_time : createTimeMs ,
75+ update_time : createTimeMs
76+ } )
6277}
6378
6479function makeRunningTaskWithStart (
6580 id : string ,
66- index : number ,
81+ priority : number ,
6782 startedSecondsAgo : number
6883) : TaskItemImpl {
6984 const start = Date . now ( ) - startedSecondsAgo * 1000
70- const status : TaskStatus = {
71- status_str : 'success' ,
72- completed : false ,
73- messages : [ [ 'execution_start' , { prompt_id : id , timestamp : start } as any ] ]
74- }
75- return new TaskItemImpl (
76- 'Running' ,
77- [ index , id , { } , { client_id : 'c1' , create_time : start - 5000 } , [ ] ] ,
78- status
79- )
85+ return makeTask ( id , priority , {
86+ status : 'in_progress' ,
87+ create_time : start - 5000 ,
88+ update_time : start
89+ } )
8090}
8191
8292function makeHistoryTask (
8393 id : string ,
84- index : number ,
94+ priority : number ,
8595 durationSec : number ,
8696 ok : boolean ,
8797 errorMessage ?: string
8898) : TaskItemImpl {
89- const start = Date . now ( ) - durationSec * 1000 - 1000
90- const end = start + durationSec * 1000
91- const messages : TaskStatus [ 'messages' ] = ok
92- ? [
93- [ 'execution_start' , { prompt_id : id , timestamp : start } as any ] ,
94- [ 'execution_success' , { prompt_id : id , timestamp : end } as any ]
95- ]
96- : [
97- [ 'execution_start' , { prompt_id : id , timestamp : start } as any ] ,
98- [
99- 'execution_error' ,
100- {
101- prompt_id : id ,
102- timestamp : end ,
103- node_id : '1' ,
104- node_type : 'Node' ,
105- executed : [ ] ,
106- exception_message :
107- errorMessage || 'Demo error: Node failed during execution' ,
108- exception_type : 'RuntimeError' ,
109- traceback : [ ] ,
110- current_inputs : { } ,
111- current_outputs : { }
112- } as any
113- ]
114- ]
115- const status : TaskStatus = {
116- status_str : ok ? 'success' : 'error' ,
117- completed : true ,
118- messages
119- }
120- return new TaskItemImpl (
121- 'History' ,
122- [ index , id , { } , { client_id : 'c1' , create_time : start } , [ ] ] ,
123- status
124- )
99+ const now = Date . now ( )
100+ const executionEndTime = now
101+ const executionStartTime = now - durationSec * 1000
102+ return makeTask ( id , priority , {
103+ status : ok ? 'completed' : 'failed' ,
104+ create_time : executionStartTime - 5000 ,
105+ update_time : now ,
106+ execution_start_time : executionStartTime ,
107+ execution_end_time : executionEndTime ,
108+ execution_error : errorMessage
109+ ? {
110+ prompt_id : id ,
111+ timestamp : now ,
112+ node_id : '1' ,
113+ node_type : 'ExampleNode' ,
114+ exception_message : errorMessage ,
115+ exception_type : 'RuntimeError' ,
116+ traceback : [ ] ,
117+ current_inputs : { } ,
118+ current_outputs : { }
119+ }
120+ : undefined
121+ } )
125122}
126123
127124export const Queued : Story = {
@@ -140,8 +137,12 @@ export const Queued: Story = {
140137 makePendingTask ( jobId , queueIndex , Date . now ( ) - 90_000 )
141138 ]
142139 // Add some other pending jobs to give context
143- queue . pendingTasks . push ( makePendingTask ( 'job-older-1' , 100 ) )
144- queue . pendingTasks . push ( makePendingTask ( 'job-older-2' , 101 ) )
140+ queue . pendingTasks . push (
141+ makePendingTask ( 'job-older-1' , 100 , Date . now ( ) - 60_000 )
142+ )
143+ queue . pendingTasks . push (
144+ makePendingTask ( 'job-older-2' , 101 , Date . now ( ) - 30_000 )
145+ )
145146
146147 // Queued at (in metadata on prompt[4])
147148
0 commit comments