public RedisTransactionBuilder RemoveTaskMessageFromActivityQueue(TaskMessage message, string workerId) { string activityProcessingQueueKey = RedisKeyNameResolver.GetTaskActivityProcessingQueueKey(this.taskHub, workerId); string messageJson = RedisSerializer.SerializeObject(message); transaction.ListRemoveAsync(activityProcessingQueueKey, messageJson); return(this); }
public ActivityTaskHandler(string taskHub, string workerId, ConnectionMultiplexer connection) { this.workerId = workerId; this.taskHub = taskHub; this.taskLocks = new ConcurrentDictionary <int, SemaphoreSlim>(); this.redisConnection = connection; this.processingTaskQueueKey = RedisKeyNameResolver.GetTaskActivityProcessingQueueKey(this.taskHub, this.workerId); this.incomingTaskQueueKey = RedisKeyNameResolver.GetTaskActivityIncomingQueueKey(this.taskHub); this.redisLogger = new RedisLogger(this.redisConnection, this.taskHub); }
/// <inheritdoc /> public async Task AbandonTaskActivityWorkItemAsync(TaskActivityWorkItem workItem) { if (this.activityTaskManager == null) { await StartAsync(); } IDatabase redisDb = this.redisConnection.GetDatabase(); string activityProcessingQueueKey = RedisKeyNameResolver.GetTaskActivityProcessingQueueKey(this.settings.TaskHubName, this.workerGuid); string messageJson = RedisSerializer.SerializeObject(workItem.TaskMessage); await redisDb.ListRemoveAsync(activityProcessingQueueKey, messageJson); }
/// <summary> /// For now this class just cleans up all workers on the task hub, but eventually it will run in the background /// and clean up any workers that haven't proven they are alive in the last n seconds. For now it must be called BEFORE /// creating a new <see cref="ActivityTaskHandler"/>. /// </summary> /// <returns></returns> public async Task CleanupWorkersAsync() { IDatabase redisDatabase = this.redisConnection.GetDatabase(); RedisValue[] deadWorkerIds = await redisDatabase.SetMembersAsync(this.workerSetKey); foreach (string deadWorkerId in deadWorkerIds) { string processingQueueKey = RedisKeyNameResolver.GetTaskActivityProcessingQueueKey(this.taskHub, deadWorkerId); long itemsToRestore = await redisDatabase.ListLengthAsync(processingQueueKey); await this.logger.LogAsync($"Moving {itemsToRestore} from processing queue back to incoming queue"); string restoredMessage = await redisDatabase.ListRightPopLeftPushAsync(processingQueueKey, incomingActivityQueueKey); while (restoredMessage != null) { TaskMessage message = RedisSerializer.DeserializeObject <TaskMessage>(restoredMessage); await this.logger.LogAsync($"Moved activity with id {message.Event.EventId} from processing queue back to incoming queue"); restoredMessage = await redisDatabase.ListRightPopLeftPushAsync(processingQueueKey, incomingActivityQueueKey); } } }