protected CollectionsTaskLocal _currentTask; //used in ExecuteTask and ReportTask //Step 0, Timer Loop, Outer Loop, Inner Loop void _collectionLoopTimer_Elapsed(object sender, ElapsedEventArgs e) { Logger.Log(""); Logger.Log(""); Logger.Log("----------Timer Loop ----------"); PreCollection(); while ((_collectionCapacity > 0) && _queueContainsMessages) { //RequestCollectionTasks Math.Min(_collectionCapacity, 32) List <CollectionsTaskLocal> collectionsTaskList = RequestCollectionTasks(_collectionCapacity); if (collectionsTaskList.Count <CollectionsTaskLocal>() > 0) { foreach (CollectionsTaskLocal taskIn in collectionsTaskList) { _collectionCapacity--; _currentTask = taskIn; ExecuteCollectionTask(); ReportCollectionTask(); StorageClientHelper.DeleteQueueMessage(QueueType.Collections, SourceType.Twitter, _currentTask.QueueMessage); } } else { Logger.Log("Received zero messages"); _queueContainsMessages = false; } } PostCollection(); }
public void ProccesCollectionTasks() { bool loop = true; while (loop) { IEnumerable <CloudQueueMessage> queueMessages = StorageClientHelper.GetQueueMessages(QueueType.Processing, SourceType.Twitter, 32); int messageCount = queueMessages.Count <CloudQueueMessage>(); if ((messageCount < 1) || (messageCount == null)) { Console.WriteLine("No Messages"); loop = false; } else { Console.WriteLine("GetQueueMessage = " + queueMessages.Count <CloudQueueMessage>()); foreach (CloudQueueMessage queueMessage in queueMessages) { //1. Get Queue HaystackLibrary.CollectionTask newTask = CollectionsTaskHelper.MessageToDatabaseTask(queueMessage.AsString); string taskString = CollectionsTaskHelper.DatabaseTaskString(newTask); Console.WriteLine(taskString); //2. Get Blob CloudBlob blob = StorageClientHelper.GetBlobReference(newTask.Project, newTask.BlobName); string blobText = blob.DownloadText(); //TODO: Blob Validate Hash Console.WriteLine(blobText); //3. Update Database: Results //TODO: Update Database: Results //4. Update Database: Tasks LinqToSqlDataContext context = new LinqToSqlDataContext(); CollectionTask oldTask = (from t in context.CollectionTasks where t.Id == newTask.Id orderby t.Id descending select t).First <CollectionTask>(); oldTask.State = CollectionsTaskState.Processed.ToString(); oldTask.Collected = newTask.Collected; oldTask.Station = newTask.Station; oldTask.Collector = newTask.Collector; oldTask.BlobName = newTask.BlobName; oldTask.BlobHash = blob.Attributes.Properties.ContentMD5; oldTask.Processed = DateTime.UtcNow; context.SubmitChanges(); //5. Update Blob Metadata blob.Attributes.Metadata["State"] = CollectionsTaskState.Processed.ToString(); //6. Delete Queue StorageClientHelper.DeleteQueueMessage(QueueType.Processing, SourceType.Twitter, queueMessage); //7. Print Success string output = CollectionsTaskHelper.DatabaseTaskString(newTask); Console.WriteLine(output); } } } }