GithubHelp home page GithubHelp logo

egg-bus's People

Contributors

anson2048 avatar helsonxiao avatar mywei1989 avatar seekcx avatar superlbr avatar windmemory avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

egg-bus's Issues

default queue name在集群redis场景中引起频繁报错

报错:BRPOPLPUSH ReplyError: ERR 'BRPOPLPUSH' command keys must in same slot
node_modules/_redis-parser@3.0.0@redis-parser/lib/parser.js:302:14) {
command: {
name: 'brpoplpush',
args: [ 'bull:default:wait', 'bull:default:active', '5' ]
}
}

原因是集群版lua脚本的使用并不同于单机版,为了保持事务,同一个lua脚本访问应该访问同一个slot,但是redis集群会根据KEY进行hash并取模,因此如果采用默认hash的话,那么就会产生这个错误,解决方案是在key也就是queue的名字上加上{}。

但是在

'default',
这一行并没有按照config里传的default name参创建default queue,导致无法用{}解决集群redis hash的问题。

简单来说只要这儿按照config里传的default queue name命名default queue,或者default queue的名字上加上{},问题就能解决

Job's run object can't waiting for a promise return

Hello,

I have a problem, it's my sample code below:

async run(data, job) {
   try {
     await this.app.mysql.get('xxx'); // this will return a promise
     let eth_transaciton = await  web3.eth.sendSignedTransaction(row_data); // can't get the promise from this function, and catch doesn't work
     console.log('xxx'); // this doesn't work
   } catch {
     log('err');
   }
}

I can't get the promise from the "web3.eth.sendSignedTransaction" function, but other function work well, do you know what's going on?

thanks a lot :)

emit 无法传递 error 对象

job1

// ...
async failed(data: any, error: Error) {
    this.app.bus.emit('jobFailed', {
      // 期望在事件中可拿到错误信息
      error,
    });
  }

截屏2022-11-07 下午5 38 34

jobFailed listener

 async run(event: any) {
  // event.data 中的 error 为空对象
}

截屏2022-11-07 下午5 39 29

emit 中的 data 并非不能传递复杂对象,似乎是只对 error 对象做了此限制。可否麻烦改下使其能够正常传递 error 对象?

How to create a job?

Hello,

I'd like to know how to create a job, could you give me an example?

thank you.

请问你是怎么处理多次重试失败job

例如:因为数据库短时不可用的原因导致job多次重试不可用, 现在修复好数据库后。然后怎样去重试这些失败后的job。有什么好的建议吗?你们是怎么处理类似的问题的?

感谢大佬!!!

Can not successfully load queue config

I was not able to successfully load the queue config.

Then I found the reason is that the internal config load code will add prefix defined in the config to the queue name, then egg-bus will not be able to locate the correct config.

Example:

I have a job file inside job folder

// /app/job/schedule.ts
import { Job } from 'egg-bus';

export default class DemoJob extends Job {
  static get queue() {
    return 'schedule'; // 使用的队列名称
  }

  static get attempts() {
    return 5; // 重试次数
  }

  async run(data, job) {
    const { ctx } = this;
    ctx.logger.info(`Receive data: ${data}, job: ${job}`);
  }

  failed(data) {
    const { ctx } = this;
    ctx.logger.info(`Failed data: ${data}`);
  }
}

Here is the config file

config.bus = {
    debug: true, // Debug 模式下会打印更多日志信息
    concurrency: 1, // Bull 中队列处理的并发数:https://github.com/OptimalBits/bull/blob/develop/REFERENCE.md#queueprocess
    listener: {
      baseDir: 'listener',
      options: { // Bull Job 配置: https://github.com/OptimalBits/bull/blob/develop/REFERENCE.md#queueadd
        attempts: 5,
        backoff: {
          delay: 3000,
          type: 'fixed',
        },
      },
    },
    job: {
      options: { // Bull Job 配置: https://github.com/OptimalBits/bull/blob/develop/REFERENCE.md#queueadd
        attempts: 5,
        backoff: {
          delay: 3000,
          type: 'fixed',
        },
      },
    },
    bull: { // Bull 队列配置:https://github.com/OptimalBits/bull/blob/develop/REFERENCE.md#queue
      redis: {
        host: 'localhost',
        port: 6379,
        db: 0,
      },
    },
    queues: {
      schedule: {
        limiter: {
          max: 1,
          duration: 1000,
        },
      },
    },
  };

Then the config won't work, there is no rateLimit for the queue.

I dig into the code a little, and print out the queue name when loading the config file, then I found it was bus:schedule, after I change the queue name in queues to bus:schedule, everything works fine. So I think it would be better to fix this, since this is not quite clear that the config needs to include the prefix.

如何监听 job 的 complete 事件?

我这里有个执行时间比较长的 job,希望能监听到 bull 的 queue 的 completed 事件,以便在某个 job 完成后再执行下一个 job。请问根据目前的版本有办法实现嘛?

Redis使用密码验证时报错

[egg-bus] bull error: ReplyError: NOAUTH Authentication required.

然而我找遍这个项目demo,居然没有任何一处使用密码。

bull: { // Bull 队列配置:https://github.com/OptimalBits/bull/blob/develop/REFERENCE.md#queue redis: { port: 6379, // Redis port host: '127.0.0.1', // Redis host db: 1, password: 'Super123456', }, },

我参考了bull文档添加了密码,依然报错。

为了证明我的redis环境没有问题,我在同一个项目使用了egg-redis 是可以正常连接并使用的。

是否可以将bus挂载在agent上?

考虑一种情况,某任务分为几个步骤,未完整执行完的情况下服务重启了
如何从特定步骤开始重新执行(重试)?
如果只能在worker(app.js)中使用bus对象,在多进程部署情况下还将考虑加锁以避免多worker同时执行.
目前只能通过定时任务 设置type为worker 确保某单一worker执行重试,不过为何要引入定时任务呢.
如果能在agent上发起重试步骤或许可以解决这个问题.
发起了一个pr https://github.com/hexindai/egg-bus/pull/31
请看看是否可以合并进入

设置某个Job只push不run

类似如下设置,跳过queue.process

  queues: {
    default: {
      push_only: false // 便于拆分生产、消费节点
    }
  }

Job 和 Listener 的区别?

除了调用方式和目录不一样,Job 和 Listener 的区别是什么?
什么场景下适合使用 Job,什么场景下适合使用 Listener?
最佳实践是什么?

有时无法访问到 this.app.mysql

在 Listener 中添加方法访问 this.app.mysql,观察到诡异的情况:有几次能正常访问,有时则提示
TypeError: Cannot read property 'queryOne' of undefined

类似下图,前两次正常执行,最后一次突然出现错误提示。
image

app.bus.get 无法获取queue队列

job文件

class BaseQueue extends Job {
  static get queue() {
    return 'accessTokenSchedule'; // 使用的队列名称
  }

  async run(info) {
    try {
      const queue = await this.app.bus.get('accessTokenSchedule');
      console.log('queue->>', queue);
    } catch (error) {
      console.log(error);
    }
  }
}

触发

      app.bus.dispatch(
        'accessTokenSchedule',
        {}
        // {
        //   repeat: {
        //     every: 10000,
        //     limit: 10,
        //   },
        // }
      );

queue为undefined

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.