handler.go ×6

Frontier kind: Code frontier

unlabeled · c_fa6dfa0f1b98

5 tests · 3074 LOC · 149 files · introduces 0 tests · 82 LOC · 4 files

Introduces — evidence that enters the hierarchy at this concept

Code
16 ranges82 lines · 4 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
505 ranges3074 lines · 149 files · Browse complete extent
All tests (intent)
5 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

4 files ranked by introduced lines: 82 introduced LOC across 16 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/service/worker/scanner/taskqueue/scavenger.go 27 introduced LOC · 5 ranges

Open complete file

148
149 for _, item := range resp.Items {
150 > atomic.AddInt64(&s.stats.taskqueue.nProcessed, 1) scavenger.go
151 > if !s.executor.Submit(s.newTask(item)) {
152 return
153 }
164
165 // process is a callback function that gets invoked from within the executor.Run() method
166 > func (s *Scavenger) process(key *p.TaskQueueKey, state *taskQueueState) executor.TaskStatus { scavenger.go
167 > return s.deleteHandler(key, state)
168 > }
169
170 func (s *Scavenger) awaitExecutor() {
171 outstanding := s.executor.TaskCount()
172 for outstanding > 0 {
173 > timer := time.NewTimer(executorPollInterval) scavenger.go
174 > select {
175 > case <-timer.C:
176 > outstanding = s.executor.TaskCount()
177 > metrics.TaskQueueOutstandingCount.With(s.metricsHandler).Record(float64(outstanding))
178 case <-s.stopC:
179 timer.Stop()
191
192 // newTask returns a new instance of an executable task which will process a single task queue
193 > func (s *Scavenger) newTask(info *p.PersistedTaskQueueInfo) executor.Task { scavenger.go
194 > return &executorTask{
195 > TaskQueueKey: p.TaskQueueKey{
196 > NamespaceID: info.Data.GetNamespaceId(),
197 > TaskQueueName: info.Data.Name,
198 > TaskQueueType: info.Data.TaskType,
199 > },
200 > taskQueueState: taskQueueState{
201 > rangeID: info.RangeID,
202 > lastUpdated: info.Data.LastUpdateTime.AsTime(),
203 > },
204 > scvg: s,
205 > }
206 > }
207
208 // Run runs the task
209 > func (t *executorTask) Run() executor.TaskStatus { scavenger.go
210 > return t.scvg.process(&t.TaskQueueKey, &t.taskQueueState)
211 > }
go.temporal.io/server/service/worker/scanner/taskqueue/handler.go 21 introduced LOC · 6 ranges

Open complete file

37 // - If the number of tasks retrieved is less than batchSize, there are no more tasks in the task queue
38 // Try deleting the task queue if its idle
39 > func (s *Scavenger) deleteHandler(key *p.TaskQueueKey, state *taskQueueState) handlerStatus { handler.go
40 > var err error
41 > var nProcessed, nDeleted int
42 >
43 > defer func() { s.deleteHandlerLog(key, state, nProcessed, nDeleted, err) }()
44
45 > for nProcessed < maxTasksPerJob { handler.go
46 > resp, err1 := s.getTasks(s.lifecycleCtx, key, taskBatchSize)
47 > if err1 != nil {
48 err = err1
49 return handlerStatusErr
50 }
51
52 > nTasks := len(resp.Tasks) handler.go
53 > if nTasks == 0 {
54 s.tryDeleteTaskQueue(key, state)
55 return handlerStatusDone
56 }
57
58 > for _, task := range resp.Tasks { handler.go
59 > nProcessed++
60 > if !matching.IsTaskExpired(task) {
61 return handlerStatusDone
62 }
103 }
104
105 > func (s *Scavenger) deleteHandlerLog(key *p.TaskQueueKey, state *taskQueueState, nProcessed int, nDeleted int, err error) { handler.go
106 > atomic.AddInt64(&s.stats.task.nDeleted, int64(nDeleted))
107 > atomic.AddInt64(&s.stats.task.nProcessed, int64(nProcessed))
108 > if err != nil {
109 s.logger.Error("scavenger.deleteHandler processed.",
110 tag.Error(err), tag.WorkflowNamespaceID(key.NamespaceID), tag.WorkflowTaskQueueName(key.TaskQueueName), tag.WorkflowTaskQueueType(key.TaskQueueType), tag.NumberProcessed(nProcessed), tag.NumberDeleted(nDeleted))
111 return
112 }
113 > if nProcessed > 0 { handler.go
114 > s.logger.Info("scavenger.deleteHandler processed.",
115 > tag.WorkflowNamespaceID(key.NamespaceID), tag.WorkflowTaskQueueName(key.TaskQueueName), tag.WorkflowTaskQueueType(key.TaskQueueType), tag.NumberProcessed(nProcessed), tag.NumberDeleted(nDeleted))
116 > }
117 }
go.temporal.io/server/common/persistence/data_interfaces_mock.go 19 introduced LOC · 4 ranges

Open complete file

668
669 // CompleteTasksLessThan indicates an expected call of CompleteTasksLessThan.
670 > func (mr *MockTaskManagerMockRecorder) CompleteTasksLessThan(ctx, request any) *gomock.Call { data_interfaces_mock.go
671 > mr.mock.ctrl.T.Helper()
672 > return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CompleteTasksLessThan", reflect.TypeOf((*MockTaskManager)(nil).CompleteTasksLessThan), ctx, request)
673 > }
674
675 // CountTaskQueuesByBuildId mocks base method.
727
728 // DeleteTaskQueue indicates an expected call of DeleteTaskQueue.
729 > func (mr *MockTaskManagerMockRecorder) DeleteTaskQueue(ctx, request any) *gomock.Call { data_interfaces_mock.go
730 > mr.mock.ctrl.T.Helper()
731 > return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteTaskQueue", reflect.TypeOf((*MockTaskManager)(nil).DeleteTaskQueue), ctx, request)
732 > }
733
734 // GetName mocks base method.
792
793 // GetTasks mocks base method.
794 > func (m *MockTaskManager) GetTasks(ctx context.Context, request *GetTasksRequest) (*GetTasksResponse, error) { data_interfaces_mock.go
795 > m.ctrl.T.Helper()
796 > ret := m.ctrl.Call(m, "GetTasks", ctx, request)
797 > ret0, _ := ret[0].(*GetTasksResponse)
798 > ret1, _ := ret[1].(error)
799 > return ret0, ret1
800 > }
801
802 // GetTasks indicates an expected call of GetTasks.
803 > func (mr *MockTaskManagerMockRecorder) GetTasks(ctx, request any) *gomock.Call { data_interfaces_mock.go
804 > mr.mock.ctrl.T.Helper()
805 > return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTasks", reflect.TypeOf((*MockTaskManager)(nil).GetTasks), ctx, request)
806 > }
807
808 // ListTaskQueue mocks base method.
go.temporal.io/server/service/worker/scanner/taskqueue/db.go 15 introduced LOC · 1 range

Open complete file

42 key *p.TaskQueueKey,
43 batchSize int,
44 > ) (*p.GetTasksResponse, error) { db.go
45 > var err error
46 > var resp *p.GetTasksResponse
47 > err = s.retryForever(func() error {
48 > resp, err = s.db.GetTasks(ctx, &p.GetTasksRequest{
49 > NamespaceID: key.NamespaceID,
50 > TaskQueue: key.TaskQueueName,
51 > TaskType: key.TaskQueueType,
52 > InclusiveMinTaskID: 0, // get the first N tasks sorted by taskID
53 > ExclusiveMaxTaskID: math.MaxInt64,
54 > PageSize: batchSize,
55 > })
56 > return err
57 > })
58 > return resp, err
59 }
60