我有一个简单的python应用程序来运行一些计划的作业。 我希望这些作业作为脚本连续运行。
import os
import time
import requests
from apscheduler.schedulers.blocking import BlockingScheduler
from pytz import utc
def a_get_request_to_api():
request.get("some_url")
def another_get_request_to_api():
try:
request.get("some_url")
except Exception as e:
print(e)
if __name__ == "__main__":
print('STARTING SCHEDULER ...')
# initialize Blocking Scheduler
scheduler = BlockingScheduler(timezone=utc)
# add jobs to run on scheduled time
scheduler.add_job(a_get_request_to_api, trigger='interval', hours=1, max_instances=2)
scheduler.add_job(another_get_request_to_api, trigger='interval', hours=6, max_instances=2)
print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
try:
scheduler.start()
except (KeyboardInterrupt, SystemExit) as e:
print(e)
这很好,当我直接从终端运行时可以使用。
我的Dockerfile
:
FROM python:3.6-alpine
WORKDIR /app
RUN pip install requests apscheduler pytz
CMD [ "python", "scheduler.py" ]
和一个简单的docker-compose.yml
:
version: '3'
services:
scheduler:
build: .
volumes:
- .:/app
但是当我对应用程序进行docker化并且docker-compose up
停留在attaching to
答案 0 :(得分:0)
我认为您应该尝试以分离模式运行docker-compose:
docker-compose up -d
-d, --detach Detached mode: Run containers in the background,
print new container names. Incompatible with
--abort-on-container-exit.