Beispiel #1
0
        /// <summary>
        /// Process jobs in queue
        /// </summary>
        /// <param name="uow">UnitOfWork</param>
        /// <param name="jobs">list of jobs to process</param>
        private static void ProcessJobs(Infrastructure.Interfaces.IUnitOfWork uow, IEnumerable <DownloadQueue> jobs)
        {
            foreach (DownloadQueue job in jobs)
            {
                if (job.DownloadType == Infrastructure.enums.DownloadType.Invalid)
                {
                    job.JobHasError();
                    uow.Complete();
                    continue;
                }

                // if previously processed and had an error skip it
                if (job.HasError != null)
                {
                    if (job.HasError.Value)
                    {
                        continue;
                    }
                }

                ProcessQueueJob queueJob = new ProcessQueueJob(job.Id);
                if (!queueJob.IsJobValid())
                {
                    job.JobHasError();
                    uow.Complete();
                    continue;
                }

                queueJob.ProcessJob();
            }
        }
        // This function will get triggered/executed when a new message is written
        // on an Azure Queue called queue.
        public static void ProcessQueueMessage([QueueTrigger("fitness-viewer-download-queue")] string message, TextWriter log)
        {
            Console.WriteLine(string.Format("Processing: {0}", message));

            AutoMapperConfig();

            ProcessQueueJob job = new ProcessQueueJob(Convert.ToInt32(message));

            if (!job.IsJobValid())
            {
                log.WriteLine(string.Format("Invalid job: {0}", message));
                return;
            }

            job.ProcessJob();
        }