Comments (6)
from egg-bus.
此外,有时是 this.ctx.service 中的对象无法访问到,我不得不用 this.app.createAnonymousContext();
单独创建 ctx 来保证能稳定访问到 service
from egg-bus.
今天继续调试,现在是在 listener 的 run 里
无论是 const ctx = this.app.createAnonymousContext();
访问 ctx,还是 this.ctx
- 调试时偶尔访问不到 ctx.service,再次 emit 触发后又能访问到
- 重启 egg 进程后亦有同样的问题
打印 ctx 发现,无法访问时是
egg_1 | { request:egg_1 | { method: 'GET',
egg_1 | url: '/',
egg_1 | header: { host: '127.0.0.1', 'x-forwarded-for': '127.0.0.1' } },
egg_1 | response:
egg_1 | { status: 200,
egg_1 | message: 'OK',
egg_1 | header: [Object: null prototype] {} },
egg_1 | app:
egg_1 | { env: 'local',
egg_1 | name: 'src',
egg_1 | baseDir: '/usr/src/app',
egg_1 | subdomainOffset: 2,
egg_1 | config: '<egg config>',
egg_1 | httpclient: '<egg httpclient>',
egg_1 | loggers: '<egg loggers>',
egg_1 | router: '<egg router>' },
egg_1 | originalUrl: '/',
egg_1 | req: '<original node req>',
egg_1 | res: '<original node res>',
egg_1 | socket: '<original node socket>' }
可以访问时是
egg_1 | { request:
egg_1 | { method: 'GET',
egg_1 | url: '/',
egg_1 | header: { host: '127.0.0.1', 'x-forwarded-for': '127.0.0.1' } },
egg_1 | response:
egg_1 | { status: 200,
egg_1 | message: 'OK',
egg_1 | header: [Object: null prototype] {} },
egg_1 | app:
egg_1 | { env: 'local',
egg_1 | name: 'src',
egg_1 | baseDir: '/usr/src/app',
egg_1 | subdomainOffset: 2,
egg_1 | config: '<egg config>',
egg_1 | controller: '<egg controller>',
egg_1 | httpclient: '<egg httpclient>',
egg_1 | loggers: '<egg loggers>',
egg_1 | middlewares: '<egg middlewares>',
egg_1 | router: '<egg router>',
egg_1 | serviceClasses: '<egg serviceClasses>' },
egg_1 | originalUrl: '/',
egg_1 | req: '<original node req>',
egg_1 | res: '<original node res>',
egg_1 | socket: '<original node socket>' }
区别是前者没有 ctx.app.serviceClasses,后者有。不清楚为什么 ctx.app.serviceClasses 会消失?
from egg-bus.
初步判断可能是和 worker 有关,稍后确认一下,感谢反馈。
from egg-bus.
app.mysql 无法访问
在 mysql
配置中将 agent
设置为 true
,默认是 false
。
config.mysql = {
client: {
host: 'localhost',
port: '3306',
user: 'root',
password: 'secret',
database: 'test',
},
app: true,
agent: true, // <-- 置为 true
};
service 无法访问
这是由 agent
引起的,在项目目录下创建一个 agent.js
就可以复现这个问题:
'use strict';
module.exports = app => {
const ctx = app.createAnonymousContext();
console.log(ctx.service); // undefined
};
目前无法确定是写法不对还是 egg 的 bug,已经提交相关 issue 至 egg(eggjs/egg#3946),等待反馈结果。
可以先自己手动使用 app.createAnonymousContext()
创建 ctx
。
from egg-bus.
有时无法访问到ctx.service。。。
from egg-bus.
Related Issues (20)
- Job's run object can't waiting for a promise return
- 请问你是怎么处理多次重试失败job HOT 2
- Job 和 Listener 的区别? HOT 2
- 不是用 TypeScript 构建的 egg 项目可以使用吗 HOT 2
- Can not successfully load queue config HOT 3
- default queue name在集群redis场景中引起频繁报错 HOT 1
- app.bus.get 无法获取queue队列 HOT 2
- Redis使用密码验证时报错 HOT 1
- 已处理的,多久会删除? HOT 1
- 针对不同的job设置不同的并发数 HOT 3
- 升级bull 4.x HOT 1
- 设置某个Job只push不run HOT 2
- 大佬 已经给你点Star 请问下 如何通过api获取到当前队列待消费的数量 HOT 8
- emit 无法传递 error 对象 HOT 2
- 如何监听 job 的 complete 事件? HOT 3
- 是否可以将bus挂载在agent上? HOT 1
- 新版多worker无法获取到service HOT 3
- 不影响请求,队列任务执行的过程中不阻塞请求 HOT 2
- 在Job的failed函数里,无法通过 this.ctx 和 this.app 分别获取 egg 的 Context 和 Application 对象吗?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from egg-bus.