1+ import { CommandKitTask , CreateTaskOptions , UpdateTaskOptions } from './driver' ;
12import { TaskManager } from './TaskManager' ;
23
34export type JSONEncodable =
@@ -18,17 +19,81 @@ export interface TaskDefinition {
1819export class TaskContextManager {
1920 public constructor ( private manager : TaskManager ) { }
2021
21- public async create ( task : TaskDefinition ) { }
22+ /**
23+ * Create a new dynamic task
24+ * @param task Task definition
25+ * @returns The created task
26+ */
27+ public async create ( task : TaskDefinition ) : Promise < CommandKitTask > {
28+ const driver = this . manager . getDriver ( ) ;
29+ if ( ! driver ) {
30+ throw new Error ( 'Task driver not configured' ) ;
31+ }
2232
23- public async cancel ( task : string ) { }
33+ const executor = this . manager . getExecutor ( task . name ) ;
34+ if ( ! executor ) {
35+ throw new Error ( `Task '${ task . name } ' not found` ) ;
36+ }
2437
25- public async complete ( task : string ) { }
38+ const options : CreateTaskOptions = {
39+ name : task . name ,
40+ id : task . id || `${ task . name } :${ Date . now ( ) } ` ,
41+ data : task . data ,
42+ duration : task . duration ,
43+ } ;
2644
27- public async fail ( task : string ) { }
45+ return driver . createTask ( options , executor ) ;
46+ }
47+
48+ /**
49+ * Cancel a task by its ID
50+ * @param taskId The ID of the task to cancel
51+ * @returns Whether the task was successfully canceled
52+ */
53+ public async cancel ( taskId : string ) : Promise < boolean > {
54+ const driver = this . manager . getDriver ( ) ;
55+ if ( ! driver ) {
56+ throw new Error ( 'Task driver not configured' ) ;
57+ }
58+
59+ return driver . cancelTask ( taskId ) ;
60+ }
61+
62+ /**
63+ * Immediately invoke a task
64+ * @param taskId The ID of the task to invoke
65+ * @param data Optional data to pass to the task
66+ */
67+ public async invoke ( taskId : string , data ?: JSONEncodable ) : Promise < void > {
68+ const driver = this . manager . getDriver ( ) ;
69+ if ( ! driver ) {
70+ throw new Error ( 'Task driver not configured' ) ;
71+ }
2872
29- public async invoke ( task : string , data : JSONEncodable ) { }
73+ await driver . invokeTask ( taskId , data ) ;
74+ }
3075
31- public async update ( task : string , data : JSONEncodable ) { }
76+ /**
77+ * Update an existing task
78+ * @param taskId The ID of the task to update
79+ * @param options Update options including data and/or duration
80+ * @returns The updated task
81+ */
82+ public async update (
83+ taskId : string ,
84+ options : UpdateTaskOptions ,
85+ ) : Promise < CommandKitTask > {
86+ const driver = this . manager . getDriver ( ) ;
87+ if ( ! driver ) {
88+ throw new Error ( 'Task driver not configured' ) ;
89+ }
90+
91+ return driver . updateTask ( taskId , options ) ;
92+ }
93+
94+ public async complete ( task : string ) { }
95+
96+ public async fail ( task : string ) { }
3297
3398 public async get ( task : string ) { }
3499
0 commit comments