Skip to main content

A small example package

Project description

habot

A Python package to run highly available Telegram bots

Usage

Install habot with pip:

pip install -i https://test.pypi.org/simple/ habot

(Habot will move to proper pypi at some later date)

Then import and you have two interesting functions available for you code:

import habot
habot.bot.run_primary_backup_model(updater, instances)
habot.bot.run_bot_only(updater)

Of these the latter will only start_polling() and idle() for an Updater of a Telegram bot made using python-telegram-bot package.

run_primary_backup_model will in addition to the bot run a primary-backup system between the instances. The instance is a list of IPs or host/domain names. The workings of the primary-backup model are described in the section below.

How the primary-backup model works

In the primary-backup model, bot code can be started for multiple instances. Primary is the instance that has become primary with the lowest timestamp.

First every instance starts looking for a primary. In case ans instance can find no primary:

  1. The instance becomes primary with its current timestamp
  2. The instance starts broadcasting that timestamp for other instances by spawning a HTTP server thread
  3. Another thread of the instance keeps looking for potential alternative primary with a lower timestamp
  4. A watcher thread checks that the other two threads remain alive.
  5. Bot code is started in the main thread.

In case the instance does find a primary, it just keeps periodically looking for a primary in the main thread.

If the primary instance A finds another instance B that has become primary with lower timestamp:

  1. A stops all its threads.
  2. And restarts the cycle by looking for a primary instance.

Security

The instances communicate between themselves over HTTP

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

habot-0.0.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

habot-0.0.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file habot-0.0.1.tar.gz.

File metadata

  • Download URL: habot-0.0.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for habot-0.0.1.tar.gz
Algorithm Hash digest
SHA256 0cd07c4b83de90711ff85356a5b2296e64663d13ba7723ce4de234ec347a0b69
MD5 dd4e06ba21ec60548e24493313ffa607
BLAKE2b-256 2262344aa8790ed065b31b19248cdd374615754b68fa5990604a1073bf2cbbc9

See more details on using hashes here.

File details

Details for the file habot-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: habot-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for habot-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3a4e4d6b1fb26c365e682183fc16e8cd42e31e5deef9f4f9ff5c3ac192f977a9
MD5 b2fd5be918ce942b4d1197aea3a00dc3
BLAKE2b-256 57bb9e21d044353a4ea958688304207a0298ccb0bff3e26f31d7955defd5deed

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page