Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: task had been submitted but not executed #355

Open
3 tasks done
RyanChen1997 opened this issue Jan 15, 2025 · 4 comments
Open
3 tasks done

[Bug]: task had been submitted but not executed #355

RyanChen1997 opened this issue Jan 15, 2025 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@RyanChen1997
Copy link

Actions I've taken before I'm here

  • I've thoroughly read the documentations on this issue but still have no clue.
  • I've searched the current list of Github issues but didn't find any duplicate issues that have been solved.
  • I've searched the internet with this issue, but haven't found anything helpful.

What happened?

I submit task successfully, but the task is not executed.

Init pool:

func InitPool() {
	var err error
	GoPool, err = ants.NewPool(11, ants.WithPanicHandler(
		func(i interface{}) {
			stack := string(debug.Stack())
			llog.Errorf(context.Background(), "[GoPool] panic: %v | Stack Trace:%s", i, stack)
		},
	))
	if err != nil {
		llog.Fatalf(context.Background(), "init GoPool failed: %s", err)
	}
}

submit task

func run() {
        ctx := context.TODO()
	task, err := db.GetReadyTasks(ctx)
	if err != nil {
		llog.Errorf(ctx, "[TriedDrivingDetectCron] get ready tasks failed: %v", err)
	}
	for _, task := range task {
		err = db.DelDataProcessTaskByTaskKey(ctx, task.TaskKey, db.DataProcessTaskTypeTiredDriving)
		if err != nil {
			llog.Errorf(ctx, "[TriedDrivingDetectCron] del task failed task: %+v err: %v", task, err)
			continue
		}
		llog.WithContext(ctx).Infof("[TriedDrivingDetectCron] start detect task. TaskKey=%s, TaskType=%d", task.TaskKey, task.TaskType)
		err = pool.GoPool.Submit(func() {
			llog.WithContext(ctx).Debugf("[TriedDrivingDetectCron] start detect goroutine. taskKey=%s", task.TaskKey)
			_, err := TiredDrivingDetect(ctx, task)
			if err != nil && !errors.Is(err, ErrOrderIsNotOnGoing) {
				llog.Errorf(ctx, "[TriedDrivingDetectCron] detect failed: %v. taskKey=%s", err, task.TaskKey)
			}
		})
		if err != nil {
			llog.Errorf(ctx, "[TriedDrivingDetectCron] submit task failed: %v. taskKey=%s", err, task.TaskKey)
		} else {
			llog.WithContext(ctx).Debugf("[TriedDrivingDetectCron] end detect task. TaskKey=%s, TaskType=%d", task.TaskKey, task.TaskType)
		}
	}
}

func TiredDrivingDetect(ctx context.Context, task db.DataProcessTask) (result DetectCounter, err error) {
	llog.WithContext(ctx).Debugf("[tiredDrivingDetect] get task: %+v", task)
	var detail TiredDrivingTaskDetail

	err = jsoniter.UnmarshalFromString(task.Detail, &detail)
	if err != nil {
		llog.Errorf(ctx, "[TriedDrivingDetectCron] parse detail failed: %v. detail=%s", err, task.Detail)
		return
	}
...
}

get log like this:
image

Major version of ants

v1

Specific version of ants

v1.3.0

Operating system

Linux

OS version

Linux 5.10.134-17.3.al8.x86_64 x86_64

Go version

go1.20.13

Relevant log output

It is mentioned above

Code snippets (optional)

No response

How to Reproduce

Steps to reproduce the behavior:

  1. Go to '....'
  2. Click on '....'
  3. Do '....'
  4. See '....'

Does this issue reproduce with the latest release?

It can reproduce with the latest release

@RyanChen1997 RyanChen1997 added the bug Something isn't working label Jan 15, 2025
@panjf2000
Copy link
Owner

Please upgrade to v2, v1 is no longer maintained.

@RyanChen1997
Copy link
Author

Please upgrade to v2, v1 is no longer maintained.

I have try v2, it has the same issue.

@panjf2000
Copy link
Owner

What specific v2 version have you tried?

@panjf2000
Copy link
Owner

Your example involved too much business logic, please provide a reproducer without these business logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants