Skip to content

Commit 114b193

Browse files
committed
simplify notifying worker
1 parent cf5d353 commit 114b193

File tree

1 file changed

+5
-30
lines changed

1 file changed

+5
-30
lines changed

backend/monoprocess/monoprocess.go

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,14 @@ func (b *monoprocessBackend) CompleteWorkflowTask(
9191
return err
9292
}
9393

94-
hasWorkflowTasks := false
95-
hasActivityTasks := false
96-
97-
for _, e := range executedEvents {
98-
if e.Type == history.EventType_WorkflowTaskStarted {
99-
hasWorkflowTasks = true
100-
break
101-
}
102-
}
103-
for _, e := range activityEvents {
104-
if e.Type == history.EventType_ActivityScheduled {
105-
hasActivityTasks = true
106-
break
107-
}
94+
if len(activityEvents) > 0 {
95+
b.notifyActivityWorker(ctx)
10896
}
97+
10998
for _, e := range timerEvents {
11099
attr, ok := e.Attributes.(*history.TimerFiredAttributes)
111100
if !ok {
112-
b.logger.Warn("unknown attributes type in timer event", "type", reflect.TypeOf(e.Attributes).String())
101+
b.logger.WarnContext(ctx, "unknown attributes type in timer event", "type", reflect.TypeOf(e.Attributes).String())
113102
continue
114103
}
115104
b.logger.DebugContext(ctx, "scheduling timer to notify workflow worker")
@@ -118,22 +107,8 @@ func (b *monoprocessBackend) CompleteWorkflowTask(
118107
// and continue.
119108
time.AfterFunc(attr.At.Sub(time.Now()), func() { b.notifyWorkflowWorker(context.Background()) })
120109
}
121-
for _, e := range workflowEvents {
122-
if e.HistoryEvent.Type == history.EventType_WorkflowExecutionStarted ||
123-
e.HistoryEvent.Type == history.EventType_SubWorkflowCompleted ||
124-
e.HistoryEvent.Type == history.EventType_WorkflowExecutionCanceled {
125-
hasWorkflowTasks = true
126-
break
127-
}
128-
}
129110

130-
// notify workers about potential new tasks
131-
if hasWorkflowTasks {
132-
b.notifyWorkflowWorker(ctx)
133-
}
134-
if hasActivityTasks {
135-
b.notifyActivityWorker(ctx)
136-
}
111+
b.notifyWorkflowWorker(ctx)
137112
return nil
138113
}
139114

0 commit comments

Comments
 (0)