Exemple #1
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            while (true)
            {
                foreach (var item in ServiceProcess.GetBatch())
                {
                    FeriadosPromaxModel result = await ServiceFeriado.FindById(item.Id);

                    if (result.NomeFeriado is not null && result.NomePais is not null)
                    {
                        var bifrostModel  = FeriadosDTO.TransferData(result);
                        var output        = OutputModel.Build(item.Timestamp, GetOperationEnum(item.Operator), "feriado", bifrostModel);
                        var resultPublish = Broker.PublishToQueue(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(output)), "PROMAX_VISITA_FERIADO");

                        if (resultPublish)
                        {
                            if (!await ServiceProcess.DeleteById(item.Id))
                            {
                                throw new Exception($"Id {item.Id} Not Found");
                            }
                        }
                    }
                }

                Task.Delay(5000).Wait();
            }
        }
        public IEnumerable <FeriadosPromaxModel> GetBatch()
        {
            var result = Repository.GetBatch();
            List <FeriadosBifrostModel> listOfFeriados = new List <FeriadosBifrostModel>();

            foreach (var entityModel in result)
            {
                var model = FeriadosDTO.TransferData(entityModel);
                yield return((FeriadosPromaxModel)model);
            }
        }