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   荣锋亮  阅读(35)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2021-02-02 cube.js playground暴露的几个不错的功能
2021-02-02 cube.js 生产集成使用的几点说明
2021-02-02 cube.js 上线文 filter 处理的原理
2020-02-02 golang 条件编译
2019-02-02 cget cmake 包管理工具
2019-02-02 buckaroo 试用
2019-02-02 buckaroo 去中心化的c++包管理工具

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示