- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2024 04:36 AM
// Função para formatar a data no padrão que a API espera (YYYY-MM-DD HH:mm:ss)
const formatDate = (date: Date): string => {
return format(date, 'yyyy-MM-dd HH:mm:ss'); // Formato necessário para a API
};
// Pegando o início e o fim do dia atual (meia-noite até 23:59:59) em UTC
const inicioDia = startOfDay(new Date()).toISOString(); // ISO format UTC
const fimDia = endOfDay(new Date()).toISOString(); // ISO format UTC
// Convertendo as datas do formato ISO para o formato necessário (YYYY-MM-DD HH:mm:ss)
const startDia = formatDate(new Date(inicioDia)); // Meia-noite de hoje no formato necessário
const endDia = formatDate(new Date(fimDia)); // 23:59:59 de hoje no formato necessário
// Crie a query combinada (busca por `opened_at`, `sys_updated_on` ou `closed_at` no dia de hoje)
// const betweenOpenedAt = `sys_created_onBETWEENjavascript:gs.dateGenerate('${startDia}')@javascript:gs.dateGenerate('${endDia}')`;
const betweenOpenedAt = `sys_created_on>=javascript:gs.dateGenerate('${startDia}')^sys_created_on<=javascript:gs.dateGenerate('${endDia}')`;
const betweenUpdatedAt = `sys_updated_onBETWEENjavascript:gs.dateGenerate('${startDia}')@javascript:gs.dateGenerate('${endDia}')`;
const betweenClosedAt = `closed_atBETWEENjavascript:gs.dateGenerate('${startDia}')@javascript:gs.dateGenerate('${endDia}')`;
const orderby = 'ORDERBYopened_at'; // ordem crescente
// const limit = 'sysparm_limit=25000' //limita a busca
Next, I'm creating an API that pulls data from ServiceNow and sends it to the database. This API runs with a cron job. I'm pulling data from a URL and a job instance that I don't have direct access to. Initially, I used BETWEEN to bring data in a 24-hour interval from the current day, from the moment it was created until it was closed.
Here's my problem. For some reason that I don't know, every time the program is running on the server and midnight comes, it stops collecting created data. It runs normally all day, but when it changes from one day to the next, it no longer collects new records. I thought it was something in the code or on the server, but when I looked, the update field was still running and being collected. After midnight, no more new records arrive, but the fields that are already in the database are updated.
At the moment, to deal with this I have to log into the server, enter the API folder, run a docker-compose down and remove the server folder, and then put it back there and run a docker-compose up -d, that is, I have to kill the application and put it back so that it can get the day's data.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2024 10:10 AM
a função que faz a formatação das datas tinha q ser passada dentro do cron e o start dia e end dia são parametros da função principal, era isso o problema
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2024 10:10 AM
a função que faz a formatação das datas tinha q ser passada dentro do cron e o start dia e end dia são parametros da função principal, era isso o problema