Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION]task立即调用任务提示「MidwayDefinitionNotFoundError: queueMap in class QueueService is not valid in current context」 #1692

Closed
xmsz opened this issue Feb 12, 2022 · 5 comments

Comments

@xmsz
Copy link

xmsz commented Feb 12, 2022

背景

    import { QueueService } from '@midwayjs/task';
    
...

  async onReady(container: IMidwayContainer) {
    const result = await container.getAsync(QueueService);
    console.log(result);
  }

...

提示

2022-02-12 14:58:51,442 INFO 7560 [@midwayjs/cloudBaseManager] server connecting act-20220208-wl-4ganbdfk30dfa1f1

MidwayDefinitionNotFoundError: queueMap in class QueueService is not valid in current context
    at MidwayContainer.getAsync (node_modules/.pnpm/@midwayjs+core@3.0.4_@midwayjs+decorator@3.0.4/node_modules/@midwayjs/core/dist/context/container.js:426:19)
    at RefResolver.resolveAsync (node_modules/.pnpm/@midwayjs+core@3.0.4_@midwayjs+decorator@3.0.4/node_modules/@midwayjs/core/dist/context/managedResolverFactory.js:34:37)
    at ManagedResolverFactory.resolveManagedAsync (node_modules/.pnpm/@midwayjs+core@3.0.4_@midwayjs+decorator@3.0.4/node_modules/@midwayjs/core/dist/context/managedResolverFactory.js:68:25)
    at ManagedResolverFactory.createAsync (node_modules/.pnpm/@midwayjs+core@3.0.4_@midwayjs+decorator@3.0.4/node_modules/@midwayjs/core/dist/context/managedResolverFactory.js:208:44) {
  code: 'MIDWAY_10003',
  cause: undefined,
  [Symbol(#NotFoundError)]: Symbol(#NotFoundError)
}
@czy88840616
Copy link
Member

是configuration里没imports task吧

@xmsz
Copy link
Author

xmsz commented Feb 12, 2022

是configuration里没imports task吧

有imports task

@czy88840616
Copy link
Member

我复现了,像是有bug。

czy88840616 added a commit that referenced this issue Feb 13, 2022
@xmsz
Copy link
Author

xmsz commented Feb 14, 2022

更新了版本现在调用提示


[ Midway ] (node:2203) UnhandledPromiseRejectionWarning: Error: Validation error, cannot resolve alias "und"
    at app/main/service/node_modules/.pnpm/cron-parser@4.2.1/node_modules/cron-parser/lib/expression.js:169:17
    at String.replace (<anonymous>)
    at Function._parseField (app/main/service/node_modules/.pnpm/cron-parser@4.2.1/node_modules/cron-parser/lib/expression.js:163:21)
    at parse (app/main/service/node_modules/.pnpm/cron-parser@4.2.1/node_modules/cron-parser/lib/expression.js:866:36)
    at Function.parse (app/main/service/node_modules/.pnpm/cron-parser@4.2.1/node_modules/cron-parser/lib/expression.js:919:10)
    at Function.parseExpression (app/main/service/node_modules/.pnpm/cron-parser@4.2.1/node_modules/cron-parser/lib/parser.js:41:25)
    at getNextMillis (app/main/service/node_modules/.pnpm/bull@4.5.3/node_modules/bull/lib/repeatable.js:214:29)
    at Queue.nextRepeatableJob (app/main/service/node_modules/.pnpm/bull@4.5.3/node_modules/bull/lib/repeatable.js:38:24)
    at app/main/service/node_modules/.pnpm/bull@4.5.3/node_modules/bull/lib/queue.js:722:19
(Use `node --trace-warnings ...` to show where the warning was created)

[ Midway ] (node:2203) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2203) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

// configuration.ts
   const result = await container.getAsync(QueueService);
    const job = result.getQueueTask('TradeTask', 'checkRefundTask');
    job.add({}, { delay: 0 });

// tradeTask

  @Task({
    repeat: { cron: FORMAT.CRONTAB.EVERY_PER_10_MINUTE },
  })
  async checkRefundTask() {
    // STEP: 执行任务
  }

@czy88840616
Copy link
Member

怎么感觉像是cron脚本解析失败..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants