简体   繁体   English

Appengine后端关机挂钩是否是随机的?

[英]Are appengine backend shutdown hooks random?

I am having problem with shutdown code. 我的关机代码有问题。 So I made a minimal backend servlet to test this. 因此,我做了一个最小的后端servlet来测试这一点。

Anyone out there that knows if shutdown hooks are reliable or not!? 有人知道关机挂钩是否可靠!!

My logs do not show any _ah/stop line at all ... at the moment. 我的日志目前根本不显示任何_ah / stop行。

I suspect that it could be related to that the logs disappears but would like to get that confirmed. 我怀疑这可能与日志消失有关,但希望得到确认。 Ie that ApiProxi.flushLogs() does not work in shutdown mode. 也就是说, ApiProxi.flushLogs()在关机模式下不起作用。

One funny note is that when I got mad and duplicated the line (15 times) ... 一个有趣的注释是,当我生气并复制线路(15次)时...

            log.info("LIFECYCLE - Shutdown hook invoked");

... I saw _ah/stop lines. ...我看到了_ah /停止线。

@Override
public void destroy() {
    super.destroy();
    log.info("LIFECYCLE - Shutting down");
    ApiProxy.flushLogs();
}

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    log.info("doGet()");
    ApiProxy.flushLogs();
}

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    log.info("doPost()");
    ApiProxy.flushLogs();
}




@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    log.info("LIFECYCLE - Starting up");
    ApiProxy.flushLogs();
    LifecycleManager.getInstance().setShutdownHook(new ShutdownHook() {
        public void shutdown() {
            log.info("LIFECYCLE - Shutdown hook invoked");
            ApiProxy.flushLogs();
        }
    });
}
@Override
public void destroy() {
    super.destroy();
    log.info("LIFECYCLE - Shutting down");
    ApiProxy.flushLogs();
}

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    log.info("doGet()");
    ApiProxy.flushLogs();
}

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    log.info("doPost()");
    ApiProxy.flushLogs();
}

Did you read the manual? 您阅读了手册吗?

https://developers.google.com/appengine/docs/java/backends/?hl=en#Shutdown https://developers.google.com/appengine/docs/java/backends/?hl=zh-CN#Shutdown

You can manually shutdown your backend to trigger the shutdown handler. 您可以手动关闭后端以触发关闭处理程序。 But yes, they can happen randomly. 但是,可以随机发生。

It does seem that the shutdown handler is not guaranteed to be called. 似乎不能保证关闭处理程序会被调用。 This happens to my app almost all the time. 这几乎总是发生在我的应用程序上。 I am using python2.7 and register a shutdown handler to log some information. 我正在使用python2.7并注册一个关闭处理程序以记录一些信息。 Does not get called 95% of the time. 95%的时间没有被调用。 Backend log says proces terminated as backend took too long to shut down. 后端日志显示,由于后端关闭时间过长,因此进程终止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM