Esempio n. 1
0
        public BatchWrite <TEntity> GetBatchWrite(TEntity entity, DynamoDbBatchOperator batchOperator)
        {
            using DynamoDBContext context = GetContext();
            BatchWrite <TEntity> batch = context.CreateBatchWrite <TEntity>();

            switch (batchOperator)
            {
            case DynamoDbBatchOperator.Delete:
                batch.AddDeleteItem(entity);
                break;

            case DynamoDbBatchOperator.Put:
                batch.AddPutItem(entity);
                break;
            }
            return(batch);
        }
Esempio n. 2
0
        private async Task LoadData(IEnumerable <DashboardEventRaw> data, string source)
        {
            if (data == null)
            {
                this._context.LogError("Null was provided to LoadData, no data to load.");
                return;
            }

            BatchWrite <DashboardEventParsed> batch = ddbContext.CreateBatchWrite <DashboardEventParsed>();

            int misses = 0;

            foreach (DashboardEventRaw item in data)
            {
                DashboardEventParsed parsed;

                try
                {
                    parsed = DashboardEventParsed.FromRawEvent(item);
                    batch.AddPutItem(parsed);

                    if (parsed.Timeline.StartTimeWasFoundInDescription == false)
                    {
                        this._context.LogError($"Did not find start/end in description: {item.Description}");
                        misses += 1;
                    }
                }
                catch (Exception e)
                {
                    this._context.LogError(e);
                }
            }

            try
            {
                await batch.ExecuteAsync();
            }
            catch (Exception e)
            {
                this._context.LogError(e);
            }

            await cwClient.PutMetricDataAsync(new PutMetricDataRequest()
            {
                MetricData = new List <MetricDatum>()
                {
                    new MetricDatum()
                    {
                        Value        = misses,
                        MetricName   = Environment.GetEnvironmentVariable("ExtractionFailureMetricName"),
                        TimestampUtc = DateTime.UtcNow,
                        Unit         = StandardUnit.Count,
                        Dimensions   = new List <Dimension>()
                        {
                            new Dimension()
                            {
                                Name  = "source",
                                Value = source
                            }
                        }
                    }
                },
                Namespace = "SHD"
            });
        }