Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

109
Vistas
Test multiple parsing outputs instead of hardcoding each of them into a constant Node js

So in my application I am cron parsing multiple database data and I have it right now to where I create a const run for each data to find the dag_id and test the determineCron one at a time manually. How would I make an array so that the "determineCron()" at the bottom will test every run instead of me just manually coding determineCron(run), determineCron(run2), determineCron(run3), determineCron(run4) etc.

const run = {
    start_date: '2022-07-01T13:45:01.221636+00:00',
        end_date: '2022-07-01T14:11:01.864293+00:00',
    state: 'success',
    dag_run_id: 'scheduled__2022-06-30T13:45:00+00:00',
    dag_id: 'IPP_CYCLE_PARMS',
}

const run2 = {
    start_date: '2022-06-26T23:00:00.742495+00:00',
    end_date: '2022-06-27T14:10:23.108401+00:00',
    state: 'failed',
    dag_run_id: 'scheduled__2022-06-25T23:00:00+00:00',
    dag_id: 'EFS-Winning-Route-daily-batch'
}

async function determineCron(result){
    /*dagID = result?.[0]?.dag_id || 0*/
    dagID = result ? result.dag_id : 0
    console.log(dagID)
    job = await bqConnection().query(`SELECT * FROM \`np-inventory-planning-thd.IPP_SLA.expected_sla\` where dag_id = "${dagID}"`)
    console.log(job[0][0]);
    cronTime = job[0][0].cron_time
    var interval = parser.parseExpression(cronTime);
    console.log('Date: ', interval.next().toString());
}
determineCron(run)
determineCron(run2)

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

const runs = [
{
    start_date: '2022-07-01T13:45:01.221636+00:00',
        end_date: '2022-07-01T14:11:01.864293+00:00',
    state: 'success',
    dag_run_id: 'scheduled__2022-06-30T13:45:00+00:00',
    dag_id: 'IPP_CYCLE_PARMS',
},
{
    start_date: '2022-06-26T23:00:00.742495+00:00',
    end_date: '2022-06-27T14:10:23.108401+00:00',
    state: 'failed',
    dag_run_id: 'scheduled__2022-06-25T23:00:00+00:00',
    dag_id: 'EFS-Winning-Route-daily-batch'
}
]
runs.forEach(determineCron)
about 4 years ago · Juan Pablo Isaza Denunciar

0

Put your runs into an array and then use array.forEach, like this:

interface CronRun {
  start_date: string;
  end_date: string;
  state: string;
  dag_run_id: string;
  dag_id: string;
}

const runs: CronRun[] = [
  {
    start_date: '2022-07-01T13:45:01.221636+00:00',
    end_date: '2022-07-01T14:11:01.864293+00:00',
    state: 'success',
    dag_run_id: 'scheduled__2022-06-30T13:45:00+00:00',
    dag_id: 'IPP_CYCLE_PARMS',
  },
  {
    start_date: '2022-06-26T23:00:00.742495+00:00',
    end_date: '2022-06-27T14:10:23.108401+00:00',
    state: 'failed',
    dag_run_id: 'scheduled__2022-06-25T23:00:00+00:00',
    dag_id: 'EFS-Winning-Route-daily-batch'
  }
];

async function determineCron(result: ChronRun){
    /*dagID = result?.[0]?.dag_id || 0*/
    dagID = result ? result.dag_id : 0
    console.log(dagID)
    job = await bqConnection().query(`SELECT * FROM \`np-inventory-planning-thd.IPP_SLA.expected_sla\` where dag_id = "${dagID}"`)
    console.log(job[0][0]);
    cronTime = job[0][0].cron_time
    var interval = parser.parseExpression(cronTime);
    console.log('Date: ', interval.next().toString());
}

runs.forEach(determineCron);

like your original code, this will run them all in parallel. If you want them in serial you'll have to do

for await (const run of runs) {
  determineCron(run);
}

instead.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You could create an array with the references of the constants, but it's tricky after that, because if you use any built-in array method like map, forEach, reduce... to execute the function it will not await the previous finish to execute the next call. Therefore, what you should do is to use for and their respective variations..

// if you are in a async scope you can remove that self invoked function

(async function () {
  const runs = [
    {
      start_date: "2022-07-01T13:45:01.221636+00:00",
      end_date: "2022-07-01T14:11:01.864293+00:00",
      state: "success",
      dag_run_id: "scheduled__2022-06-30T13:45:00+00:00",
      dag_id: "IPP_CYCLE_PARMS",
    },
    {
      start_date: "2022-06-26T23:00:00.742495+00:00",
      end_date: "2022-06-27T14:10:23.108401+00:00",
      state: "failed",
      dag_run_id: "scheduled__2022-06-25T23:00:00+00:00",
      dag_id: "EFS-Winning-Route-daily-batch",
    },
  ];

  async function determineCron(result) {
    /*dagID = result?.[0]?.dag_id || 0*/
    dagID = result ? result.dag_id : 0;
    console.log(dagID);
    job = await bqConnection().query(
      `SELECT * FROM \`np-inventory-planning-thd.IPP_SLA.expected_sla\` where dag_id = "${dagID}"`
    );
    console.log(job[0][0]);
    cronTime = job[0][0].cron_time;
    var interval = parser.parseExpression(cronTime);
    console.log("Date: ", interval.next().toString());
  }

  for (let run of runs) {
    await determineCron(run);
  }
})();
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda