public async Task SubscribeToIterativeTagAsync(string iterativeTag, string userId, string token, string endpointArn, Platform platform) { string tag = iterativeTag; if (string.IsNullOrEmpty(tag)) { return; } DynamoTag pnTag = await tagTableOperator.GetTagAsync(iterativeTag); if (pnTag != null && pnTag.TaggingTypeEnum != PNTagType.Iterative) { throw new OverrideExistingTagTypeException(pnTag.Tag, pnTag.TaggingTypeEnum.ToString()); } if (pnTag == null) { pnTag = new DynamoTag(); pnTag.Tag = iterativeTag; pnTag.TaggingTypeEnum = PNTagType.Iterative; await tagTableOperator.AddTagAsync(pnTag); } Func <DateTime?> calculateTTL = (() => { if (Provider.IterativeTagTimeToLive.HasValue) { return(DateTime.UtcNow.Add(Provider.IterativeTagTimeToLive.Value)); } return(null); }); DynamoIterativeTag entry = new DynamoIterativeTag { Tag = tag, Subscriber = new Subscriber { UserId = userId, Token = token }, EndpointArn = endpointArn, Platform = platform, ttl = calculateTTL() }; await iterativeTagTableOperator.AddSubscriberAsync(entry); // await tagTableService.IncrementNumberOfSubscribers(pnTag.Tag, 1); }
private async Task RemoveUnsuccessfulEndpoints(IterativeTagResponseTuple resultTuples) { // Parallel tasks are not implemented because of AWS-SDK SNS bug in parellel execution cause high memory usage // List<Task> tasks = new List<Task>(); foreach (var responseTagTuple in resultTuples) { PublishToSNSResult result = responseTagTuple.Item1; DynamoIterativeTag tag = responseTagTuple.Item2; if (result.ErrorAlias == ErrorReason.SNSEndpointDisabled || result.ErrorAlias == ErrorReason.SNSEndpointNotFound) { await unRegisterService.UnRegisterSubscriberAsync(tag.Subscriber.UserId, tag.Subscriber.Token); } } }