Compare commits

...

2 Commits

Author SHA1 Message Date
b3b2217115 fix scheduler 2023-04-18 21:10:34 +03:00
d88ef52c53 fix scheduler 2023-04-18 20:16:52 +03:00
5 changed files with 15 additions and 6 deletions

View File

@ -22,7 +22,16 @@ sudo systemctl start mosgortrans.service
python main.py python main.py
``` ```
- change bash bot-start.sh to python main.py - set `START_WITH_WEBHOOK` to blank
## Delete or set webhook manually
url: https://api.telegram.org/bot{TELEGRAM_TOKEN}/{method}Webhook?url={WEBHOOK_URL}
methods:
- delete
- set
## Local development clean: ## Local development clean:

View File

@ -5,13 +5,11 @@ WEBHOOK_HOST="https://mydomain.com"
WEBHOOK_PATH="/transport" WEBHOOK_PATH="/transport"
# webserver settings # webserver settings
WEBAPP_HOST="127.0.0.1" WEBAPP_HOST="0.0.0.0"
WEBAPP_PORT="8080" WEBAPP_PORT="8080"
# set to true to start with webhook. Else bot will start on polling method # set to true to start with webhook. Else bot will start on polling method
START_WITH_WEBHOOK="true" START_WITH_WEBHOOK="true"
GECKO_DRIVER_VERSION="0.32.0"
# chat ids for scheduler tasks # chat ids for scheduler tasks
CHAT_IDS="123456789,987654321" CHAT_IDS="123456789,987654321"

View File

@ -27,7 +27,7 @@ class Application:
TELEGRAM_API_TOKEN, '{TELEGRAM_API_TOKEN}' TELEGRAM_API_TOKEN, '{TELEGRAM_API_TOKEN}'
) )
) )
bot_scheduler.start() self.scheduler.start()
async def _on_shutdown(self, dp: Dispatcher) -> None: async def _on_shutdown(self, dp: Dispatcher) -> None:
logger.warning('Shutting down..') logger.warning('Shutting down..')

View File

@ -47,12 +47,13 @@ bot_cron_jobs = {
class BotScheduler: class BotScheduler:
scheduler = AsyncIOScheduler()
def __init__( def __init__(
self, self,
cron_jobs: dict[str, dict[str, Any]], cron_jobs: dict[str, dict[str, Any]],
): ):
self.cron_jobs = cron_jobs self.cron_jobs = cron_jobs
self.scheduler = AsyncIOScheduler()
def add_scheduler_jobs(self, jobs_name: str) -> None: def add_scheduler_jobs(self, jobs_name: str) -> None:
cron_jobs = self.cron_jobs.get(jobs_name) cron_jobs = self.cron_jobs.get(jobs_name)

View File

@ -21,4 +21,5 @@ if __name__ == '__main__':
if START_WITH_WEBHOOK: if START_WITH_WEBHOOK:
web.run_app(app=app, host=WEBAPP_HOST, port=WEBAPP_PORT) web.run_app(app=app, host=WEBAPP_HOST, port=WEBAPP_PORT)
else: else:
application.scheduler.start()
application.bot_polling() application.bot_polling()