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

94
Vistas
the parameters passed in node-schedule job function is overwrite by the later one

I use schedule to create a class named Schedule,the code is below:

import * as schedule from "node-schedule";
import { switchStationExecuteStore } from '../controller/SwitchStation'
export class Schedule {
  executionId: any;
  time: any;
  deviceParams:any
  nodeType: any;
  nodeName: any;
  constructor(time,executionId,nodeName,nodeType,deviceParams) {
    this.time = time
    this.executionId = executionId
    this.deviceParams = deviceParams
    this.nodeName = nodeName
    this.nodeType = nodeType
  }
  startJob() {
    console.log(this.deviceParams.deviceId)
    schedule.scheduleJob(this.time, function (executionId,nodeName,nodeType,deviceParams) {
      switchStationExecuteStore[executionId].toExecuteDevice(nodeName, nodeType, deviceParams)
    }.bind(null,this.executionId,this.nodeName, this.nodeType, this.deviceParams))
  }
}

And in other file, I use the Schedule class,the code is

 const that = this
 const job = new Schedule(cornTime,this.executionId,nodeName, nodeType, deviceParams)
 job.startJob()

when the code will be execte in the sametime and exectue two times with different deviceParams, the later deviceParams will overwrite the first one,so in the toExecuteDevice function I will always get the later value.

I wonder what's wrong in my code? and how can I do to fix it.Thanks so much

about 4 years ago · Juan Pablo Isaza
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