Open
Description
User Story
As a developer, I want providers to be immediately removed from the queue when their node is turned off, so that the system does not route orders to unavailable providers.
Acceptance Criteria
-
GIVEN a provider's
IsAvailable
status is set tofalse
WHEN the provider profile is updated
THEN the provider should be removed from all relevant Redis queues. -
GIVEN a provider is removed from the queue
WHEN the Redis operation fails
THEN an error should be logged, and the provider profile update should still proceed.
Tech Details
-
Modify the
UpdateProviderProfile
function to:- Check if
IsAvailable
is being set tofalse
. - If
IsAvailable
is set tofalse
, search for and remove the provider from all relevant Redis queues.
- Check if
-
Use the provided Redis logic to:
- Search for the provider in the queue using
LIndex
. - Replace the provider's entry with a placeholder (
DELETED_PROVIDER
). - Remove all occurrences of the placeholder using
LRem
.
- Search for the provider in the queue using
-
Ensure the Redis operations are atomic and do not block the provider profile update.
Example removal from redis:
// Remove provider from Redis queues
redisKey := fmt.Sprintf("bucket_%s_%s_%s", provider.Edges.Currency.Code, provider.Edges.ProvisionBucket.MinAmount, provider.Edges.ProvisionBucket.MaxAmount)
for index := -1; ; index-- {
providerData, err := storage.RedisClient.LIndex(ctx, redisKey, int64(index)).Result()
if err != nil {
break
}
parts := strings.Split(providerData, ":")
if len(parts) != 5 {
logger.Errorf("invalid provider data format: %s", providerData)
continue
}
if parts[0] == provider.ID {
placeholder := "DELETED_PROVIDER"
_, err := storage.RedisClient.LSet(ctx, redisKey, int64(index), placeholder).Result()
if err != nil {
logger.Errorf("failed to set placeholder at index %d: %v", index, err)
}
_, err = storage.RedisClient.LRem(ctx, redisKey, 0, placeholder).Result()
if err != nil {
logger.Errorf("failed to remove placeholder from circular queue: %v", err)
}
break
}
}
Notes/Assumptions
- The Redis queue key format is
bucket_<currency>_<minAmount>_<maxAmount>
. - The provider data in Redis is stored in the format
providerID:token:rate:minAmount:maxAmount
. - The feature should handle cases where the provider is not found in the queue.
Open Questions
- Should we notify the provider when they are removed from the queue due to unavailability?