public async Task ProcessQueueMessage([QueueTrigger("tasks")] string message)
        {
            try
            {
                if (this.hub.State == ConnectionState.Disconnected)
                {
                    await this.hub.Start();
                }

                AzureTask task = JsonSerializer.Deserialize <AzureTask>(message);
                task.Duration = this.GetRandomNumber(5, 15);
                task.Status   = EnumStatus.Success;
                task.Finished = true;
                task.QRCode   = await this.CreateQRCode();

                string updatedTaskJson = JsonSerializer.Serialize(task);
                //Sending tasks to queue
                QueueClient queueClient = new QueueClient(this.config["AzureWebJobsStorage"], this.config["Queue:ResultQueueName"]);
                await queueClient.CreateIfNotExistsAsync();

                await queueClient.SendMessageAsync(updatedTaskJson);

                Console.WriteLine($"Task id:{task.Id} name:{task.Name} proccesed");

                await this.hubProxy.Invoke("BrodcastTask", updatedTaskJson);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
        public static async Task SendTask(AzureTask task)
        {
            string queueName = QueueServices.config["Queue:QueueName"];
            string taskJson  = JsonSerializer.Serialize(task);
            //Sending tasks to queue
            QueueClient queueClient = new QueueClient(QueueServices.config["AzureWebJobsStorage"], queueName);
            await queueClient.CreateIfNotExistsAsync();

            await queueClient.SendMessageAsync(taskJson);
        }
        public async Task ProcessQueueMessage([QueueTrigger("updated-tasks")] string message)
        {
            AzureTask task = JsonSerializer.Deserialize<AzureTask>(message);    
            this.unitOfWork.Tasks.Update(task);    
            await this.unitOfWork.Save();
            if (task.Finished == true)
            {
                while (DateTime.Now.Minute - task.FinishedTime.Minute < 1)
                {
                    // Wait for a minute
                }

                this.unitOfWork.Tasks.Remove(task);
                await this.unitOfWork.Save();
            }
        }
Exemplo n.º 4
0
        public async Task <ActionResult <AzureTask> > CreateTasks(string name)
        {
            try
            {
                var task = new AzureTask(name);
                this.unitOfWork.Tasks.Add(task);
                await this.unitOfWork.Save();

                await QueueServices.SendTask(task);

                return(this.Ok(task));
            }
            catch (Exception ex)
            {
                return(this.StatusCode(500, ex.Message));
            }
        }