chore: 并入 iotlcm-admin-svr 历史到 admin-svr/(原提交 49818c6)
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package lifecycle
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
type BatchExecutor interface {
|
||||
Execute(ctx context.Context, batchNo string) error
|
||||
MarkFailed(ctx context.Context, batchNo, reason string) error
|
||||
}
|
||||
|
||||
func Dispatch(executor BatchExecutor, batchNo string) {
|
||||
go func() {
|
||||
ctx := context.Background()
|
||||
defer func() {
|
||||
if recovered := recover(); recovered != nil {
|
||||
reason := fmt.Sprintf("后台执行异常: %v", recovered)
|
||||
g.Log().Errorf(ctx, "SIM lifecycle batch panic, batchNo=%s, reason=%s", batchNo, reason)
|
||||
if err := executor.MarkFailed(ctx, batchNo, reason); err != nil {
|
||||
g.Log().Errorf(ctx, "mark SIM lifecycle batch failed after panic, batchNo=%s, error=%+v", batchNo, err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
if err := executor.Execute(ctx, batchNo); err != nil {
|
||||
g.Log().Errorf(ctx, "execute SIM lifecycle batch failed, batchNo=%s, error=%+v", batchNo, err)
|
||||
if markErr := executor.MarkFailed(ctx, batchNo, err.Error()); markErr != nil {
|
||||
g.Log().Errorf(ctx, "mark SIM lifecycle batch failed, batchNo=%s, error=%+v", batchNo, markErr)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
Reference in New Issue
Block a user