Skip to content
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

Remove provider from queue when node is turned off #435

Open
chibie opened this issue Mar 18, 2025 · 1 comment · May be fixed by #443
Open

Remove provider from queue when node is turned off #435

chibie opened this issue Mar 18, 2025 · 1 comment · May be fixed by #443

Comments

@chibie
Copy link
Contributor

chibie commented Mar 18, 2025

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

  1. GIVEN a provider's IsAvailable status is set to false
    WHEN the provider profile is updated
    THEN the provider should be removed from all relevant Redis queues.

  2. 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

  1. Modify the UpdateProviderProfile function to:

    • Check if IsAvailable is being set to false.
    • If IsAvailable is set to false, search for and remove the provider from all relevant Redis queues.
  2. 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.
  3. 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

  1. The Redis queue key format is bucket_<currency>_<minAmount>_<maxAmount>.
  2. The provider data in Redis is stored in the format providerID:token:rate:minAmount:maxAmount.
  3. The feature should handle cases where the provider is not found in the queue.

Open Questions

  1. Should we notify the provider when they are removed from the queue due to unavailability?
@sundayonah
Copy link
Collaborator

Yes, providers should be notified when they are removed from the queue due to unavailability.
This notification system would serve multiple important purposes:

  • Providers can quickly identify why they're not receiving orders
  • Enables faster troubleshooting of availability issues
  • Helps maintain better system visibility @

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants