Skip to content

Commit

Permalink
added backup (#21)
Browse files Browse the repository at this point in the history
Co-authored-by: Roman <roman.rey@hawk.ai>
  • Loading branch information
rooom13 and hawk-roman-rey authored Dec 5, 2021
1 parent 75066ed commit 28a6ca6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
10 changes: 10 additions & 0 deletions daily_word_bot/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ def send_user_word(self, user: dict): # pragma: no cover

self.send_message_to_user(user, msg, reply_markup=reply_markup)

def callback_chrono_backup(self, context: CallbackContext): # pragma: no cover
self.backup_service.backup()
logger.info("Backed up!")

def send_message_to_admins(self, msg: str): # pragma: no cover
for chat_id in config.ADMIN_CHAT_IDS:
self.updater.bot.send_message(chat_id=chat_id, text=msg, parse_mode='HTML')
Expand Down Expand Up @@ -372,6 +376,12 @@ def run(self): # pragma: no cover
# second="10,20,30,40,50,0" # test
))

# daily backup
self.updater.job_queue.run_custom(self.callback_chrono_backup, job_kwargs=dict(
trigger="cron",
hour="22"
))

# Bot conversation flow logic
broadcast_handler = ConversationHandler(
entry_points=[
Expand Down
13 changes: 11 additions & 2 deletions daily_word_bot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,31 @@
"REDIS_HOST",
"WORD_BANK_LOCAL",
"VERSION",
"BACKUP_FILE_PATH_IN",
"BACKUP_FOLDER_ID_OUT",
"BACKUP_FILE_ID_OUT"
])

live_config = Config(
ADMIN_CHAT_IDS=utils.parse_admin_chat_ids_var(),
BOT_TOKEN=os.getenv("BOT_TOKEN"),
REDIS_HOST="redis",
WORD_BANK_LOCAL=False,
VERSION=os.getenv("VERSION")
VERSION=os.getenv("VERSION"),
BACKUP_FILE_PATH_IN=os.getenv("BACKUP_FILE_PATH_IN"),
BACKUP_FOLDER_ID_OUT=os.getenv("BACKUP_FOLDER_ID_OUT"),
BACKUP_FILE_ID_OUT=os.getenv("BACKUP_FILE_ID_OUT")
)

test_config = Config(
ADMIN_CHAT_IDS=utils.parse_admin_chat_ids_var(),
BOT_TOKEN=os.getenv("TEST_BOT_TOKEN"),
REDIS_HOST="localhost",
WORD_BANK_LOCAL=strtobool(os.getenv("WORD_BANK_LOCAL") or "true"),
VERSION="aVersion"
VERSION="aVersion",
BACKUP_FILE_PATH_IN=os.getenv("BACKUP_FILE_PATH_IN"),
BACKUP_FOLDER_ID_OUT=os.getenv("BACKUP_FOLDER_ID_OUT"),
BACKUP_FILE_ID_OUT=os.getenv("BACKUP_FILE_ID_OUT")
)

config = live_config if (os.getenv("ENV") or "").lower() == "live" else test_config

0 comments on commit 28a6ca6

Please sign in to comment.