【问题标题】:Heroku Java application timing out after 90 secondsHeroku Java 应用程序在 90 秒后超时
【发布时间】:2020-11-07 14:33:58
【问题描述】:

一段时间以来,我一直在尝试在 heroku 上托管一个不和谐机器人。我现在一切都设置好了,但连接在 90 秒后一直超时,因为它无法维持连接,我不确定出了什么问题。

过程文件: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 库中是否有某种方法可以解决这个问题,但到目前为止我还没有找到。

【问题讨论】:

    标签: java heroku


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2021-12-08
      • 1970-01-01
      • 2015-11-18
      • 2012-07-06
      • 1970-01-01
      • 2021-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多