Heroku Java应用程序在90秒后超时

时间:2020-07-17 18:27:53

标签: java heroku

一段时间以来,我一直在尝试在heroku上托管一个不和谐的bot。我现在已完成所有设置,但由于无法维持连接,并且90秒钟后连接仍会超时,我不确定什么地方出错了。

Procfile:web: java $JAVA_OPTS -Dserver.port=$PORT -cp target/classes:target/dependency/* com.marcuzzo.JDABot.Bot

错误日志:

2020-07-17T17:54:47.513540+00:00 heroku[web.1]: Starting process with command `java $JAVA_OPTS -Dserver.port=7699 -cp target/classes:target/dependency/* com.marcuzzo.JDABot.Bot`
2020-07-17T17:54:49.238091+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2020-07-17T17:54:49.241547+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2020-07-17T17:54:50.386750+00:00 app[web.1]: 938 [main] INFO net.dv8tion.jda.api.JDA - Login Successful!
2020-07-17T17:54:50.526175+00:00 app[web.1]: 1078 [JDA MainWS-WriteThread] INFO net.dv8tion.jda.internal.requests.WebSocketClient - Connected to WebSocket
2020-07-17T17:54:50.862291+00:00 app[web.1]: 1414 [JDA MainWS-ReadThread] INFO net.dv8tion.jda.api.JDA - Finished Loading!
2020-07-17T17:56:18.105532+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch
2020-07-17T17:56:18.120426+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-07-17T17:56:18.198101+00:00 heroku[web.1]: Process exited with status 137
2020-07-17T17:56:18.243205+00:00 heroku[web.1]: State changed from starting to crashed

有人告诉我将procfile中的dyno更改为web之后的其他任何东西,但是在构建成功的同时,如果我使用类似bot的东西,则该漫游器永远不会在线。

这个post告诉我调用listen()方法,但是我认为这是为python编写的,或者是我不知道的库的一部分。

考虑到我只专注于托管它,我的应用程序很短:

package com.marcuzzo.JDABot;

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;

public class Bot {

    public static void main (String[] args) {

        int port = Integer.parseInt(System.getenv("PORT"));
    //  String host = "0.0.0.0";
        
        String token = "insert token here";
        try {
            JDA jda = JDABuilder.createDefault(token).build();
            
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

我不确定我正在使用的JDA库中是否有解决该问题的方法,但到目前为止我还没有找到任何方法。

1 个答案:

答案 0 :(得分:1)

看起来您的机器人不是网络应用。您应该使用worker heroku配置。请检查https://devcenter.heroku.com/articles/run-non-web-java-processes-on-heroku