actionherojs 生产部署说明

actionherojs 支持集群以及ha 模式,同时支持web 与worker分离

参考图

 

 

woker&web分离配置

/ Assume we use the flag \`process.env.ACTIONHERO_ROLE\` to denote the type of server
// You can set this variable in the ENV of your server or launch each process with the flag:
// Worker => \`ACTIONHERO_ROLE='worker' npm start\`
// Server => \`ACTIONHERO_ROLE='server' npm start\`
 
// config/tasks.ts
 
exports.production = {
  tasks: function () {
    // default to config for 'server'
    let config = {
      scheduler: false,
      queues: ["*"],
      verbose: true,
      // ...
    };
 
    if (process.env.ACTIONHERO_ROLE === "worker") {
      config.scheduler = true;
      config.minTaskProcessors = 1;
      config.maxTaskProcessors = 10;
    }
 
    return config;
  },
};
 
// config/web.ts
 
exports.default = {
  web: function () {
    config = {
      enabled: true,
      secure: false,
      serverOptions: {},
      port: process.env.PORT || 8080,
      // ...
    };
 
    if (process.env.ACTIONHERO_ROLE === "worker") {
      config.enabled = false;
    }
 
    return config;
  },
};

说明

官方文档是比较值得阅读的,里边包含了好多生产环境的最佳实践

参考资料

https://www.actionherojs.com/tutorials/production-notes

posted on 2022-02-02 22:57  荣锋亮  阅读(34)  评论(0编辑  收藏  举报

导航