Cambios mensajes
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
using bdAsegasa;
|
||||
using bdAsegasa.db;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Quartz;
|
||||
using Quartz.Impl;
|
||||
using Servicio_Gestion_Asegasa.Procesos;
|
||||
using System.Reflection;
|
||||
using System.Reflection.Metadata;
|
||||
|
||||
namespace Servicio_Gestion_Asegasa
|
||||
{
|
||||
@@ -8,24 +14,96 @@ namespace Servicio_Gestion_Asegasa
|
||||
{
|
||||
private readonly ILogger<Worker> _logger;
|
||||
|
||||
public Worker(ILogger<Worker> logger)
|
||||
public Worker(ILogger<Worker> logger, Configuracion Conf)
|
||||
{
|
||||
_logger = logger;
|
||||
ProcesosConf.Conf = Conf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
|
||||
// await ProcesosMensajes.EnviaSMSAsync();
|
||||
string Mensaje = "Servicio Gestion Asegasa. Versi<73>n: " + tsUtilidades.Utilidades.ExtraeValorCadena(Assembly.GetExecutingAssembly().FullName, "Version");
|
||||
try
|
||||
{
|
||||
|
||||
if (ProcesosConf.Conf.HoraProcesosDiarios != null)
|
||||
{
|
||||
Mensaje += " Hora Procesos Programados: " + ProcesosConf.Conf.HoraProcesosDiarios;
|
||||
CreaTareaProcesosDiarios();
|
||||
}
|
||||
|
||||
await Logs.A<EFBFBD>adeLogAsync(tsUtilidades.Enumeraciones.TipoLog.InicioServicio, "Inicio " + Mensaje);
|
||||
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
if (_logger.IsEnabled(LogLevel.Information))
|
||||
{
|
||||
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
||||
if (_logger.IsEnabled(LogLevel.Information))
|
||||
{
|
||||
_logger.LogInformation("Servicio en ejecuci<63>n: {time}", DateTimeOffset.Now);
|
||||
//Creo q aqui se deberia llamar a los servicios
|
||||
}
|
||||
await ProcesosConf.ProcesarAsync();
|
||||
await System.Threading.Tasks.Task.Delay(1000 * 60 * 5, stoppingToken);
|
||||
}
|
||||
await Task.Delay(1000, stoppingToken);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// Logs.A<>adeLog(tsUtilidades.Enumeraciones.TipoLog.FinServicio, "Detenci<63>n " + Mensaje);
|
||||
// When the stopping token is canceled, for example, a call made from services.msc,
|
||||
// we shouldn't exit with a non-zero exit code. In other words, this is expected...
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "{Message}", ex.Message);
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void CreaTareaProcesosDiarios()
|
||||
{
|
||||
ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
|
||||
IScheduler scheduler = schedulerFactory.GetScheduler().Result;
|
||||
scheduler.Start().Wait();
|
||||
// Crear un trabajo
|
||||
IJobDetail job = JobBuilder.Create<TareasProgramadas>()
|
||||
.WithIdentity("TareasProgramadas", "Grupo1")
|
||||
.Build();
|
||||
// Crear un trigger que se ejecute diariamente a una hora espec<65>fica
|
||||
|
||||
|
||||
int Hora = int.Parse(ProcesosConf.Conf.HoraProcesosDiarios.Split(":")[0]);
|
||||
int Minutos = int.Parse(ProcesosConf.Conf.HoraProcesosDiarios.Split(":")[1]);
|
||||
Quartz.ITrigger trigger = Quartz.TriggerBuilder.Create()
|
||||
.WithIdentity("TareasProgramadas", "Grupo1")
|
||||
.StartAt(DateBuilder.TodayAt(Hora, Minutos, 0))
|
||||
.WithSimpleSchedule(x => x
|
||||
.WithIntervalInHours(24)
|
||||
.RepeatForever())
|
||||
.Build();
|
||||
|
||||
// Programar el trabajo con el trigger
|
||||
scheduler.ScheduleJob(job, trigger).Wait();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class TareasProgramadas : IJob
|
||||
{
|
||||
public Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
//var ch = bdTecnosis.db.chequeos;
|
||||
// var bd = bdTecnosis.tscTecnosis.NuevoContexto();
|
||||
//var c = bd.chequeos.FirstOrDefault(x => x.idChequeo == ch.idChequeo);
|
||||
//Comprobaciones.ChequeaColaCorreo(bd,c);
|
||||
//Comprobaciones.CompruebaReplica();
|
||||
//Aqui van los procesos y comprobaciones
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user