-
-
Notifications
You must be signed in to change notification settings - Fork 762
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
Upgrade go-redis/redis to version 8 #298
Conversation
TODO: I tested with a local redis docker container and all was well. However my redis cluster is in AWS (Elasticache). There were several test failures around date/time stamps being slightly off or task scores being off by one or two. My guess is these are due to a test design which requires a specific setup, probably locally. @hibiken do you have a recommended cluster setup for testing locally? |
Codecov Report
@@ Coverage Diff @@
## master #298 +/- ##
=======================================
Coverage 73.25% 73.25%
=======================================
Files 20 20
Lines 2632 2632
=======================================
Hits 1928 1928
Misses 496 496
Partials 208 208
Continue to review full report at Codecov.
|
client.go
Outdated
@@ -265,7 +266,7 @@ func (c *Client) Close() error { | |||
// By deafult, max retry is set to 25 and timeout is set to 30 minutes. | |||
// | |||
// If no ProcessAt or ProcessIn options are provided, the task will be pending immediately. | |||
func (c *Client) Enqueue(task *Task, opts ...Option) (*TaskInfo, error) { | |||
func (c *Client) Enqueue(ctx context.Context, task *Task, opts ...Option) (*TaskInfo, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not against it, but I'm not sure if we want to make this API change in this PR.
Unless you have a strong argument for this, I'll make internal changes without changing the public API of the package.
internal/base/base.go
Outdated
Ping(context.Context) error | ||
Enqueue(ctx context.Context, msg *TaskMessage) error | ||
EnqueueUnique(ctx context.Context, msg *TaskMessage, ttl time.Duration) error | ||
Dequeue(ctx context.Context, qnames ...string) (*TaskMessage, time.Time, error) | ||
Done(ctx context.Context, msg *TaskMessage) error | ||
Requeue(ctx context.Context, msg *TaskMessage) error | ||
Schedule(ctx context.Context, msg *TaskMessage, processAt time.Time) error | ||
ScheduleUnique(ctx context.Context, msg *TaskMessage, processAt time.Time, ttl time.Duration) error | ||
Retry(ctx context.Context, msg *TaskMessage, processAt time.Time, errMsg string) error | ||
Archive(ctx context.Context, msg *TaskMessage, errMsg string) error | ||
ForwardIfReady(ctx context.Context, qnames ...string) error | ||
ListDeadlineExceeded(ctx context.Context, deadline time.Time, qnames ...string) ([]*TaskMessage, error) | ||
WriteServerState(ctx context.Context, info *ServerInfo, workers []*WorkerInfo, ttl time.Duration) error | ||
ClearServerState(ctx context.Context, host string, pid int, serverID string) error | ||
CancelationPubSub(ctx context.Context) (*redis.PubSub, error) // TODO: Need to decouple from redis to support other brokers | ||
PublishCancelation(ctx context.Context, id string) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to change the interface Broker unless we need to.
scheduler.go
Outdated
if err != nil { | ||
j.logger.Errorf("scheduler could not record enqueue event of enqueued task %+v: %v", j.task, err) | ||
} | ||
} | ||
|
||
// Register registers a task to be enqueued on the given schedule specified by the cronspec. | ||
// It returns an ID of the newly registered entry. | ||
func (s *Scheduler) Register(cronspec string, task *Task, opts ...Option) (entryID string, err error) { | ||
func (s *Scheduler) Register(ctx context.Context, cronspec string, task *Task, opts ...Option) (entryID string, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. I'd wait to see if we need to make this API change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this!
Do you have a reason for changing public API in this PR? Do you think users of the package will use context for deadlines, cancelation, etc?
I think we can focus just on upgrading the redis library version in this PR, so that changes are only scoped to internal/rdb
package and shouldn't affect rest of the codebase.
What do you think?
I'm not opposed to keeping the exported API as is. I'm not as familiar with the internal operation of the module, so wasn't sure if we can make assumptions about the context we pass to the underlying redis library. Would we just pass |
Probably we should just pass see: |
Yes I like those approaches, which we can add down the road. I'll back out the exported API changes in the next couple days and switch to using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@strobus thank you for working one this.
One last change request:
I prefer to avoid creating a globally scoped variable ctx
(both in tests and application code).
Would you mind changing it so that the scope of the variable is limited to a method or a redis command invocation? (you can just call context.Background()
or context.TODO()
at the call site)
I am happy to do it. This project is a crucial component in what I'm working on, so thank you for developing this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for going back and forth so many times (hopefully this is the last time!)
I added two comments. please take a look!
Also, it looks like this branch needs to be rebased on master.
Looks like conflicts still need to be resolved in internal/rdb/inspect.go. |
Ah yes, missed that. |
@strobus Thank you for the hard work and patience to address all the comments 🎉 Merging the PR now. |
This PR upgrade the
go-redis/redis/v7
dependency togo-redis/redis/v8
. The major change between the two versions is that all methods that interact with the redis server have acontext.Context
parameter added. These context parameters have been surfaced up to the exportedasynq
interfaces.Edit: resolves issue #293