[GH-ISSUE #605] How can I get worker name #2320

Open
opened 2026-03-15 20:04:33 +03:00 by kerem · 8 comments
Owner

Originally created by @tracydzf on GitHub (Jan 12, 2023).
Original GitHub issue: https://github.com/hibiken/asynq/issues/605

excuse me! i want to get woker name in handler.Becauese i want to log which is woking,who exec this task.
tasks.Logger.With().Str("task_id", taskId).Str("task_type", t.Type()).Logger()
image@hibiken

Originally created by @tracydzf on GitHub (Jan 12, 2023). Original GitHub issue: https://github.com/hibiken/asynq/issues/605 excuse me! i want to get woker name in handler.Becauese i want to log which is woking,who exec this task. `tasks.Logger.With().Str("task_id", taskId).Str("task_type", t.Type()).Logger()` ![image](https://user-images.githubusercontent.com/36504268/212027447-a0508707-7115-4696-8468-b9a210431dd8.png)@hibiken
Author
Owner

@tracydzf commented on GitHub (Jan 12, 2023):

@hibiken

<!-- gh-comment-id:1380054833 --> @tracydzf commented on GitHub (Jan 12, 2023): @hibiken
Author
Owner

@tracydzf commented on GitHub (Jan 13, 2023):

i kown i can use os.hostname and os.PID。but i want get worker uuid。
image
thanks

<!-- gh-comment-id:1381176141 --> @tracydzf commented on GitHub (Jan 13, 2023): i kown i can use os.hostname and os.PID。but i want get worker uuid。 ![image](https://user-images.githubusercontent.com/36504268/212213328-4d810db0-bbbb-4ef6-854e-d7f99474575e.png) thanks
Author
Owner

@linhbkhn95 commented on GitHub (Feb 14, 2023):

Currently, asynq only stores workerInfo as additional information. It's really not action performed.
worker is goroutine with ID is msgID
h.workers[w.msg.ID] = w
Can you provide the specific use case for your issue?

<!-- gh-comment-id:1429100651 --> @linhbkhn95 commented on GitHub (Feb 14, 2023): Currently, asynq only stores workerInfo as additional information. It's really not action performed. worker is goroutine with ID is msgID `h.workers[w.msg.ID] = w` Can you provide the specific use case for your issue?
Author
Owner

@zss007 commented on GitHub (Mar 17, 2023):

For example, I need to send a message to a specific worker.
And now have to make sure the hostname is different. If i can get serverID's value, then hostname can be the same.

	host, err := os.Hostname()
	if err != nil {
		log.Fatalf("get hostname error is %v", err)
		return
	}
	currWorker := fmt.Sprintf("%v:%v", host, os.Getpid())

	mux := asynq.NewServeMux()
	mux.HandleFunc(currWorker, tasks.HandleSystemTask)
<!-- gh-comment-id:1473260844 --> @zss007 commented on GitHub (Mar 17, 2023): For example, I need to send a message to a specific worker. And now have to make sure the hostname is different. If i can get serverID's value, then hostname can be the same. ``` host, err := os.Hostname() if err != nil { log.Fatalf("get hostname error is %v", err) return } currWorker := fmt.Sprintf("%v:%v", host, os.Getpid()) mux := asynq.NewServeMux() mux.HandleFunc(currWorker, tasks.HandleSystemTask) ```
Author
Owner

@linhbkhn95 commented on GitHub (Mar 17, 2023):

mux.HandleFunc(currWorker, tasks.HandleSystemTask) you mean?
HandleFunc is used to set up taskType with a task handler that will have a specific schema per task. A specific handler should handle it.

<!-- gh-comment-id:1473304716 --> @linhbkhn95 commented on GitHub (Mar 17, 2023): `mux.HandleFunc(currWorker, tasks.HandleSystemTask)` you mean? `HandleFunc` is used to set up taskType with a task handler that will have a specific schema per task. A specific handler should handle it.
Author
Owner

@zss007 commented on GitHub (Mar 17, 2023):

All for send a message to a specific server, so define a special task type.
Then client can send message to this server, and other servers will not handle it.

So if i can get serverID, it's better.

<!-- gh-comment-id:1473312659 --> @zss007 commented on GitHub (Mar 17, 2023): All for send a message to a specific server, so define a special task type. Then client can send message to this server, and other servers will not handle it. So if i can get serverID, it's better.
Author
Owner

@linhbkhn95 commented on GitHub (Mar 17, 2023):

Then client can send message to this server, and other servers will not handle it.?
I really have not understood you. Low-level, tasks are stored in Redis, They will be distributed to multi workers via Redis.
I really curious that why do you need that info?

<!-- gh-comment-id:1473354698 --> @linhbkhn95 commented on GitHub (Mar 17, 2023): `Then client can send message to this server, and other servers will not handle it.`? I really have not understood you. Low-level, tasks are stored in Redis, They will be distributed to multi workers via Redis. I really curious that why do you need that info?
Author
Owner

@zss007 commented on GitHub (Mar 17, 2023):

For example, now I want to update the server code, which may run on windows or linux, and each server must only receive an update message once

<!-- gh-comment-id:1473374694 --> @zss007 commented on GitHub (Mar 17, 2023): For example, now I want to update the server code, which may run on windows or linux, and each server must only receive an update message once
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/asynq#2320
No description provided.