hibiken / asynq

Simple, reliable, and efficient distributed task queue in Go
MIT License
10k stars 714 forks source link

[FEATURE REQUEST] Support changing priority queues at runtime #850

Open linhbkhn95 opened 7 months ago

linhbkhn95 commented 7 months ago

Is your feature request related to a problem? Please describe. I use asynq at my company and rely on the frequency of the priority queue to determine task ordering. However, there are instances where this order needs to be adjusted.

 Queues: map[string]int{
        "group1": 6,
        "group2":  4
    },

->

 Queues: map[string]int{
        "group1": 4
        "group2":  6
    },

However, I cannot change it immediately in runtime. I have to restart server(pods). Moreover, my company utilizes a "Dynamic Config Loader" for updating applications at runtime. Therefore, if this feature were to be released, it would prove to be immensely useful Describe the solution you'd like


**Describe alternatives you've considered**

**Additional context**
We can see a draft solution in my repo
https://github.com/linhbkhn95/asynq/pull/6/files
@hibiken @kamikazechaser How's about think?
kamikazechaser commented 7 months ago

I can see such a feature being added if the underlying p.queueConfig map is replaced/updated in a safe way. However, this could set a precedent to update almost every underlying config at runtime 😄.

linhbkhn95 commented 7 months ago

@kamikazechaser It is a good approach for applying dynamic config loader in most company without restarting app. I also use for feature flags as a exprirement for new features. https://github.com/uber/piranha

linhbkhn95 commented 7 months ago

Hi @kamikazechaser, do u use telegram? I was just out of work, I wanna contribute more open-source project like that

kamikazechaser commented 7 months ago

Hi @kamikazechaser, do u use telegram? I was just out of work, I wanna contribute more open-source project like that

Yes. On the same username.

linhbkhn95 commented 7 months ago

I cant find it. my telegram username is linhbkhn95. Can u message me?

kamikazechaser commented 7 months ago

I cant find it. my telegram username is linhbkhn95. Can u message me?

Sent you a message from my alt, my main is kc^.

linhbkhn95 commented 7 months ago

furthermore, For dynamic config loader, if we use a logger, we can change the log level at runtime by the SetLevel method without restart pod(server)

// SetLevel alters the logging level.
func (lvl AtomicLevel) SetLevel(l zapcore.Level) {
    lvl.l.Store(int32(l))
}

https://github.com/uber-go/zap/blob/master/level.go#L122 @kamikazechaser

linhbkhn95 commented 6 months ago

Hi @hibiken @kamikazechaser Can you guys tell me about what we should do next step?

kamikazechaser commented 6 months ago

There are a lot of requests for such a feature, so why not. Something like Server.SetQueuesPriority(map[string]int) error would work. There would need to be checks for whether the new map has the same keys as the old one and whether strictPriority is enabled in the current config e.t.c. and all these behind a mutex guard.

Do you have something similar in mind?