Beispiel #1
0
        private Task SaveAsync(ContainerActiveEntity prevEntry)
        {
            TableOperation insertOperation = TableOperation.InsertOrReplace(prevEntry);

            // Execute the insert operation.
            return(_instanceTable.SafeExecuteAsync(insertOperation));
        }
Beispiel #2
0
        public async Task <Segment <ActivationEvent> > GetActiveContainerTimelineAsync(DateTime start, DateTime end, string continuationToken)
        {
            var query   = ContainerActiveEntity.GetQuery(start, end);
            var results = await _instanceTable.SafeExecuteQueryAsync(query);

            List <ActivationEvent>      l      = new List <ActivationEvent>();
            Dictionary <string, string> intern = new Dictionary <string, string>();

            foreach (var result in results)
            {
                var    name = result.GetContainerName();
                string internedName;
                if (!intern.TryGetValue(name, out internedName))
                {
                    intern[name] = name;
                    internedName = name;
                }

                var timeBucket = result.GetStartBucket();
                l.Add(new ActivationEvent
                {
                    ContainerName   = name,
                    StartTimeBucket = timeBucket,
                    StartTime       = TimeBucket.ConvertToDateTime(timeBucket),
                    Length          = result.GetLength()
                });
            }

            return(new Segment <ActivationEvent>(l.ToArray(), null));
        }
        private Task SaveAsync(ContainerActiveEntity prevEntry)
        {
            TableOperation insertOperation = TableOperation.InsertOrReplace(prevEntry);

            var instanceTable = _tableLookup.GetTableForDateTime(prevEntry.StartTime);

            // Execute the insert operation.
            return(instanceTable.SafeExecuteAsync(insertOperation));
        }
Beispiel #4
0
        // this should be the only thread writing to this container
        // Write a "active" entry every interval.
        // If a previous entry exists, then extend its duration (rather that writing many entries). That simplifies the reader.
        async Task PollerAsync()
        {
            do
            {
                try
                {
                    await Task.Delay(_interval, _cancel.Token);
                }
                catch (OperationCanceledException)
                {
                    // Don't return yet. One last chance to flush
                }

                bool hasOutstanding;
                lock (_lock)
                {
                    hasOutstanding = _outstandingCount.Count > 0;
                }

                bool active = _recent || hasOutstanding;
                _recent = false;

                if (active)
                {
                    var now = DateTime.UtcNow;

                    // If previous exists, update it
                    var currentBucket = TimeBucket.ConvertToBucket(now);
                    var prevBucket    = currentBucket - 1;

                    ContainerActiveEntity prevEntry = await TryGetAsync(prevBucket);

                    if (prevEntry == null)
                    {
                        prevEntry = await TryGetAsync(currentBucket);
                    }
                    if (prevEntry != null)
                    {
                        if (prevEntry.GetLength() > LengthThreshold)
                        {
                            prevEntry = null;
                        }
                    }

                    if (prevEntry == null)
                    {
                        prevEntry = ContainerActiveEntity.New(now, _containerName);
                    }

                    // Update the length on the previous entry
                    prevEntry.EndTime = now;
                    await SaveAsync(prevEntry);
                }
            } while (!_cancel.IsCancellationRequested);
        }
        private Task SaveAsync(ContainerActiveEntity prevEntry)
        {
            TableOperation insertOperation = TableOperation.InsertOrReplace(prevEntry);

            // Execute the insert operation.
            return _instanceTable.ExecuteAsync(insertOperation);
        }
Beispiel #6
0
 private Task <ContainerActiveEntity> TryGetAsync(long timeBucket)
 {
     return(ContainerActiveEntity.LookupAsync(_instanceTable, timeBucket, _containerName));
 }
        private Task <ContainerActiveEntity> TryGetAsync(long timeBucket)
        {
            var instanceTable = _tableLookup.GetTableForTimeBucket(timeBucket);

            return(ContainerActiveEntity.LookupAsync(instanceTable, timeBucket, _containerName));
        }