{"action":"created","issue":{"url":"https://api.github.com/repos/eggjs/egg/issues/2582","repository_url":"https://api.github.com/repos/eggjs/egg","labels_url":"https://api.github.com/repos/eggjs/egg/issues/2582/labels{/name}","comments_url":"https://api.github.com/repos/eggjs/egg/issues/2582/comments","events_url":"https://api.github.com/repos/eggjs/egg/issues/2582/events","html_url":"https://github.com/eggjs/egg/issues/2582","id":324707095,"number":2582,"title":"只执行一次的逻辑写在哪？","user":{"login":"musicode","id":2732303,"avatar_url":"https://avatars2.githubusercontent.com/u/2732303?v=4","gravatar_id":"","url":"https://api.github.com/users/musicode","html_url":"https://github.com/musicode","followers_url":"https://api.github.com/users/musicode/followers","following_url":"https://api.github.com/users/musicode/following{/other_user}","gists_url":"https://api.github.com/users/musicode/gists{/gist_id}","starred_url":"https://api.github.com/users/musicode/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/musicode/subscriptions","organizations_url":"https://api.github.com/users/musicode/orgs","repos_url":"https://api.github.com/users/musicode/repos","events_url":"https://api.github.com/users/musicode/events{/privacy}","received_events_url":"https://api.github.com/users/musicode/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-05-20T12:51:03Z","updated_at":"2018-05-21T02:52:15Z","closed_at":"2018-05-21T02:48:33Z","author_association":"NONE","body":"举个简单的例子。\r\n\r\n在 MQ 场景中，我希望在项目启动时，执行一次监听逻辑，在这个监听逻辑里，当收到消息时，我希望能调用一些 service 来完成工作，但是我发现 egg 目前的设计是，每次请求都会重新创建 service 实例。\r\n\r\n之前看文档发现 agent 貌似是执行一次的，但是我怕写在 agent 之后，万一有什么错误，把网站搞挂。\r\n\r\n此外，因为 service 是跟请求相关的，所以类似上面说的异步任务，是不是取不到 service？\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/eggjs/egg/issues/comments/390539593","html_url":"https://github.com/eggjs/egg/issues/2582#issuecomment-390539593","issue_url":"https://api.github.com/repos/eggjs/egg/issues/2582","id":390539593,"user":{"login":"musicode","id":2732303,"avatar_url":"https://avatars2.githubusercontent.com/u/2732303?v=4","gravatar_id":"","url":"https://api.github.com/users/musicode","html_url":"https://github.com/musicode","followers_url":"https://api.github.com/users/musicode/followers","following_url":"https://api.github.com/users/musicode/following{/other_user}","gists_url":"https://api.github.com/users/musicode/gists{/gist_id}","starred_url":"https://api.github.com/users/musicode/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/musicode/subscriptions","organizations_url":"https://api.github.com/users/musicode/orgs","repos_url":"https://api.github.com/users/musicode/repos","events_url":"https://api.github.com/users/musicode/events{/privacy}","received_events_url":"https://api.github.com/users/musicode/received_events","type":"User","site_admin":false},"created_at":"2018-05-21T02:52:15Z","updated_at":"2018-05-21T02:52:15Z","author_association":"NONE","body":"谢谢，这个答案很全"}}
{"actor":{"display_login":"musicode"}}