88
99#import " TaskPipelineManager.h"
1010#import " TaskItem.h"
11+ #import " AppDelegate.h"
1112
1213@implementation TaskPipelineManager
1314
1415
16+ - (void ) dealloc
17+ {
18+ [self .periodicTaskPipelineCheckTimer invalidate ];
19+ self.periodicTaskPipelineCheckTimer = NULL ;
20+ }
21+
22+
23+
24+
1525- (instancetype )init
1626{
1727 self = [super init ];
1828 if (self) {
1929 self.taskItemsArray = [NSMutableArray array ];
2030
2131 self.taskPipelineStatus = kTaskPipelineStatusIdle ;
32+
33+ self.periodicTaskPipelineCheckTimer = [NSTimer timerWithTimeInterval: 5 .0f target: self selector: @selector (periodicTaskPipelineCheckTimerFired: ) userInfo: self repeats: YES ];
34+
35+ [[NSRunLoop mainRunLoop ] addTimer: self .periodicTaskPipelineCheckTimer forMode: NSDefaultRunLoopMode ];
2236 }
2337 return self;
2438}
@@ -40,13 +54,16 @@ - (TaskItem *) makeTaskItemWithExecutable:(NSString *)executableName functionNam
4054}
4155
4256
57+
58+
4359- (void ) addTaskItem : (TaskItem *)taskItem
4460{
4561 [self .taskItemsArray addObject: taskItem];
4662}
4763
4864
4965
66+
5067- (void ) configureTaskPipes
5168{
5269 TaskItem * firstTaskItem = [self .taskItemsArray firstObject ];
@@ -90,6 +107,8 @@ - (void) configureTaskPipes
90107}
91108
92109
110+
111+
93112- (void ) startTasks
94113{
95114 for (TaskItem * taskItem in self.taskItemsArray )
@@ -113,6 +132,8 @@ - (void) startTasks
113132}
114133
115134
135+
136+
116137- (void ) terminateTasks
117138{
118139 // NSArray * reversedTaskItemsArray = [[self.taskItemsArray reverseObjectEnumerator] allObjects];
@@ -131,6 +152,39 @@ - (void) terminateTasks
131152}
132153
133154
155+
156+ - (void ) periodicTaskPipelineCheckTimerFired : (NSTimer *)timer
157+ {
158+ BOOL failedTaskFound = NO ;
159+ TaskItem * failedTaskItem = NULL ;
160+
161+ for (TaskItem * taskItem in self.taskItemsArray )
162+ {
163+ if (taskItem.task .isRunning == NO )
164+ {
165+ failedTaskFound = YES ;
166+ failedTaskItem = taskItem;
167+ break ;
168+ }
169+ }
170+
171+ if (failedTaskFound == YES )
172+ {
173+ NSLog (@" TaskPipelineManager - TaskPipelineFailed - %@ - %@ " , failedTaskItem, self.taskItemsArray );
174+
175+ [[NSNotificationCenter defaultCenter ] postNotificationName: @" TaskPipelineFailedNotification" object: self ];
176+
177+ [self terminateTasks ];
178+
179+ AppDelegate * appDelegate = (AppDelegate *)[NSApp delegate ];
180+
181+ [appDelegate updateCurrentTasksText ];
182+ }
183+ }
184+
185+
186+
187+
134188- (NSString *)tasksInfoString
135189{
136190 NSMutableString * tasksInfoString = [NSMutableString stringWithString: @" \n\n " ];
0 commit comments