1

你好我只是想使用基于网络和工作者的机器人我的意思是

main.py 与

# telegram bot
from pyrogram import Client,filters
Bot = Client(api_id,api_hash,bottoken)

@Client.on_message(filters.command("start")
async def bot_start_cmd(c,m):
   await m.reply_text("Hello I am alive")

if __name__ == '__main__':
   Bot.run() 

在另一个带有 webapp.py 的文件上

from aiohttp import web
from aiohttp import web_fileresponse,streamer
import asyncio,os
WEBFILES_DIRECTORY = "/app/webfiles/"
routes = web.RouteTableDef()

@routes.get('/')
async def index(request):
    return web.Response(text='Hello Babe!')


@streamer
async def file_sender(writer, file_path=None):
     """ This function will read large file chunk by chunk and send it through HTTP without reading them into memory """ 
     with open(file_path, 'rb') as f: 
         chunk = f.read(2 ** 16) 
         while chunk: 
               await writer.write(chunk) 
               chunk = f.read(2 ** 16)

@routes.get('/file/{file_name}')
async def download_file(request): 
    file_name = request.match_info['file_name'] 
    headers = { "Content-disposition": "attachment; filename={file_name}".format(file_name=file_name) } 
    file_path = os.path.join(WEBFILES_DIRECTORY, file_name) 
    if not os.path.exists(file_path): 
        return web.Response( body='File <{file_name}> does not exist'.format(file_name=file_name), status=404 ) 
    return web.Response( body=file_sender(file_path=file_path), headers=headers ) 

async def start_server():
    app = web.Application()
    app.add_routes(routes)
    return app

现在我只想在heroku上同时使用电报机器人和网络所以我尝试了Procfile,它只适用于网络,工人需要一个额外的Dyno,也没有我想要的效率所以我尝试用docker方式来做

像 Dockerfile 这样的东西

FROM ubuntu:20.04
RUN mkdir /app
RUN chmod 777 /app
WORKDIR /app
RUN apt -qq update
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Kolkata
RUN apt -qq install -y git wget curl busybox  python3 ffmpeg python3-pip 
COPY requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt
COPY . .
CMD ["bash","run.sh"]

run.sh 在哪里

gunicorn webapp:start_server --bind 0.0.0.0:$PORT --worker-class aiohttp.GunicornWebWorker & python3 main.py

和 heroku.yml 作为

build:
  docker:
    worker: Dockerfile
run:
  worker: bash run.sh

现在我部署了它,发现只有机器人在运行,当我访问网络时,我曾经得到过类似的东西

at=error code=H14 desc="No web processes running" method=GET path="/" host=speedtestdunia.herokuapp.com request_id=c3691fcf-11a3-4ebf-a5bd-8f6aa210fca1 fwd="27.59.96.103" dyno= connect= service= status=503 bytes= protocol=https

那么有什么好的解决方案来克服这个吗???

4

0 回答 0