2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-09-20 11:05:58 +08:00

conventions

This commit is contained in:
Binaek Sarkar 2022-02-10 15:26:34 +05:30 committed by Ken Hibino
parent 55d0610a03
commit ebd7a32c0f
4 changed files with 14 additions and 21 deletions

View File

@ -7,11 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [0.22.0] - 2022-01-29
### Added
- `BaseContext` introduced in `Config` to specify callback hook to provide a base `context` from which `Handler` `context` is derived
- `BaseContext` is introduced in `Config` to specify callback hook to provide a base `context` from which `Handler` `context` is derived
## [0.21.0] - 2022-01-22

View File

@ -54,10 +54,15 @@ func TestCreateContextWithFutureDeadline(t *testing.T) {
}
func TestCreateContextWithBaseContext(t *testing.T) {
type ctxKey string
type ctxValue string
var key ctxKey = "key"
var value ctxValue = "value"
tests := []struct {
deadline time.Time
baseCtx context.Context
}{
{time.Now().Add(-2 * time.Hour)},
{context.WithValue(context.Background(), key, value)},
}
for _, tc := range tests {
@ -66,13 +71,8 @@ func TestCreateContextWithBaseContext(t *testing.T) {
ID: uuid.NewString(),
Payload: nil,
}
type ctxKey string
type ctxValue string
var key ctxKey = "key"
var value ctxValue = "value"
baseCtx := context.WithValue(context.Background(), key, value)
ctx, cancel := New(baseCtx, msg, tc.deadline)
ctx, cancel := New(tc.baseCtx, msg, time.Now().Add(30*time.Minute))
defer cancel()
select {
@ -82,10 +82,11 @@ func TestCreateContextWithBaseContext(t *testing.T) {
}
v, ok := ctx.Value(key).(ctxValue)
original, _ := tc.baseCtx.Value(key).(ctxValue)
if !ok {
t.Errorf("ctx.Value().(ctxValue) returned false, expected to be true")
}
if v != value {
if v != original {
t.Errorf("ctx.Value().(ctxValue) returned unknown value (%v), expected to be %s", v, value)
}
}

View File

@ -27,7 +27,7 @@ type processor struct {
broker base.Broker
handler Handler
baseCtxFn BaseCtxFn
baseCtxFn func() context.Context
queueConfig map[string]int
@ -72,7 +72,7 @@ type processor struct {
type processorParams struct {
logger *log.Logger
broker base.Broker
baseCtxFn BaseCtxFn
baseCtxFn func() context.Context
retryDelayFunc RetryDelayFunc
isFailureFunc func(error) bool
syncCh chan<- *syncRequest

View File

@ -101,10 +101,7 @@ type Config struct {
//
// If BaseContext is nil, the default is context.Background().
// If this is defined, then it MUST return a non-nil context
BaseContext BaseCtxFn
// SleepOnEmptyQueue optionally specifies the amount of time to wait before polling again when there are no messages in the queue
SleepOnEmptyQueue time.Duration
BaseContext func() context.Context
// Function to calculate retry delay for a failed task.
//
@ -212,9 +209,6 @@ func (fn ErrorHandlerFunc) HandleError(ctx context.Context, task *Task, err erro
fn(ctx, task, err)
}
// BaseCtxFn provides the root context from where the execution contexts of tasks are derived
type BaseCtxFn func() context.Context
// RetryDelayFunc calculates the retry delay duration for a failed task given
// the retry count, error, and the task.
//