Example #1
0
        async Task <Job[]> LoadSuspended()
        {
            var list = new List <Job>();

            while (list.Count == 0)
            {
                try
                {
                    var max = Configuration.MaxQueueLength;

                    var items =
                        (Configuration.Type != null ?
                         _persistenceStore.LoadSuspended(Configuration.Type, max) :
                         _persistenceStore.LoadSuspended(_allActivityConfiguration.Select(c => c.Type), max))
                        .ToArray();

                    _eventStream.Publish <JobQueue>(EventType.Activity,
                                                    EventProperty.ActivityName("LoadSuspendedItemsStarted"),
                                                    EventProperty.Named("NumberOfItems", items.Length));

                    list.AddRange(items.Select(item => _jobMutator.Mutate <JobQueue>(item, suspended: false)));
                }
                catch (Exception e)
                {
                    if (e.IsFatal())
                    {
                        throw;
                    }

                    _eventStream.Publish <JobQueue>(e);
                }

                if (!list.Any())
                {
                    await Task.Delay(Configuration.RetryDelay);
                }
            }

            _eventStream.Publish <JobQueue>(EventType.Activity,
                                            EventProperty.ActivityName("LoadSuspendedItemsFinished"),
                                            EventProperty.Named("NumberOfItems", list.Count));

            return(list.ToArray());
        }