Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

90
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!