Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rama controlador #4

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
25 changes: 0 additions & 25 deletions README.md

This file was deleted.

61 changes: 54 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,60 @@
require('dotenv').config();
const cron = require('node-cron');
const express = require('express');
const app = express();
const port = process.env.PORT ?? 3000;
const port = process.env.PORT || 8000;
const controlador = require('./src/controlador_aplicacion/controlador');
const { actualizaClimaBasedeDatos } = require('./src/modelo_aplicacion/actualizabd');

app.use(express.static('public'))
app.use(express.static('public'));

app.get('*', (req, res) => {
res.redirect('/');
})
// Configura una tarea cron para ejecutar agregaInformacionCSV cada día a las 2 AM
cron.schedule('* 0 2 * * *', async () => {
try {
const direccionCSV = 'ruta/al/archivo.csv';
await actualizaBD.agregaInformacionCSV(direccionCSV);
} catch (error) {
console.error('Tarea cron: Error al actualizar la base de datos.', error);
}
}, {
scheduled: true,
timezone: "America/Mexico_City"
});

// Configura otra tarea cron para ejecutar actualizaClimaBasedeDatos cada hora
cron.schedule('* * * * * *', async () => {
try {
await actualizaBD.actualizaClimaBasedeDatos();
} catch (error) {
console.error('Tarea cron: Error al actualizar el clima en la base de datos.', error);
}
});

app.get('/', (req, res) => {
res.status(200).send('Pagina de inicio');
});

app.get('/consulta-ciudad', (req, res) => {
controlador.obtenerClimaPorCiudad(req, res, () => {
// No se muestra mensaje de terminación en la consola
});
});

app.get('/consulta-ticket', (req, res) => {
controlador.obtenerClimaPorTicket(req, res, () => {
// No se muestra mensaje de terminación en la consola
});
});

app.listen(port, () => {
console.log(`App listening on port ${port}`);
})
console.log(`Servidor corriendo en el puerto ${port}`);
console.log(new Date().toISOString());
// Configura una tarea cron para ejecutar agregaInformacionCSV cada día a las 2 AM
cron.schedule('* 0 3 * * *', async () => {
console.log(new Date().toISOString());
actualizaClimaBasedeDatos();
}, {
scheduled: true,
timezone: "America/Mexico_City"
});
});
Loading