API Limitation

Arthur Sanchez
Giga Guru

 

// 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&colon;gs.dateGenerate('${startDia}')^sys_created_on<=javascript&colon;gs.dateGenerate('${endDia}')`;

const betweenUpdatedAt = `sys_updated_onBETWEENjavascript&colon;gs.dateGenerate('${startDia}')@javascript&colon;gs.dateGenerate('${endDia}')`;

const betweenClosedAt = `closed_atBETWEENjavascript&colon;gs.dateGenerate('${startDia}')@javascript&colon;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.

I looked at the server, ran and tested the code locally several times and it has no errors, so everything leads me to believe that there must be something in the instance that is causing this problem, but I don't have access to it, and I need a way to explain to my boss why this is happening and how or where it can be resolved, I need help.
 
 
 

 

1 ACCEPTED SOLUTION

Arthur Sanchez
Giga Guru

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

View solution in original post

1 REPLY 1

Arthur Sanchez
Giga Guru

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