github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/engine/framework/internal/eventloop/interfaces.go (about) 1 // Copyright 2022 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package eventloop 15 16 import ( 17 "context" 18 ) 19 20 // Task defines the common methods used to drive both workers 21 // and masters. 22 // It will replace the current `Worker` interface in further refactors. 23 type Task interface { 24 // Init is called before entering the loop calling Poll. 25 Init(ctx context.Context) error 26 27 // Poll should be called periodically until an error is returned. 28 Poll(ctx context.Context) error 29 30 // NotifyExit does necessary bookkeeping job for exiting, 31 // such as notifying a master. 32 // errIn describes the reason for exiting. 33 NotifyExit(ctx context.Context, errIn error) error 34 35 // Close does necessary clean up. 36 // TODO `ctx` is for compatibility, remove it. 37 Close(ctx context.Context) error 38 39 // Stop is called when a task is canceled 40 Stop(ctx context.Context) error 41 42 // ID returns an identifier for the Task. 43 ID() string 44 }