node.js

node.js is a javascript runtime, which means it can execute javascript code outside of a browser.

for example, if we want call a js function interval, we can write it into a js file, and use node.js to execute it.

// 定时监控车辆数据盘是否插入边缘服务器的状态
const monitorHOtPlugEvent = () => {
  ServerVehicles.forEach((serverVehicle) => {
    const edgeServerHost = serverVehicle.server;
    const vehicle = serverVehicle.vehicle;
    const cacheKey = `hot-plug-event-${edgeServerHost}-${vehicle}`;
    console.log(cacheKey);
    const topic = `/surge/edge_server_monitor/disk/hot_plug_event_report/${edgeServerHost}/${vehicle}`;
    if (myCache.get(cacheKey) === "remove") {
      client.publish(topic, "disk is remove");
    } else if (myCache.get(cacheKey) === "add") {
      client.publish(topic, "disk is add");
    }
  });
};

// 每10分钟监控一次
setInterval(monitorHOtPlugEvent, 1000 * 60 * 10);

then we can run it by node [path to js file]

package