Skip to main content

Service Worker Framework

Project description

Robit

Chronological Automation Service Framework

A robot for your bits!

(Pronounced "Row-Bit")

Features

  • Lightweight (only one installed dependencies pytz which is also lightweight)
  • Can run with monitoring interface or headless
  • Very simple and easy to set up and configure

Interface

Screenshot

Usage

Worker

  • Code below is provided in the examples/worker_example.py file of this project.
import random
from time import sleep

import robit


robit.set_time_zone('America/Edmonton')
robit.set_database_logging(True)


def function_to_alert_me(**kwargs):
    print(f"ALARM !!!! {kwargs['alert_message']}")


wo = robit.Worker(
    name='Robit Example Worker',
    key='Your-Own-Unique-Worker-Key-That-Is-Secure',
    web_server=True,
    # web_server_address='0.0.0.0',
    # web_server_port=8000,
    alert_method=function_to_alert_me,
    alert_health_threshold=99.0,
)


def function_sleep_short():
    sleep(2)
    return 'Slept for 2 seconds'


def function_sleep_for_time(sleep_time: int):
    sleep(sleep_time)
    return f'Slept for {sleep_time} seconds'


wo.add_job(
    'Specific Sleep Period Function',
    function_sleep_for_time,
    method_kwargs={'sleep_time': 5},
    group='Sleeping',
    cron='* * * * *',
)

wo.add_job(
    'Sleep 3 Seconds Function Every 5 Seconds',
    function_sleep_for_time,
    method_kwargs={'sleep_time': 3},
    group='Sleeping',
    cron='*/5 * * * * *',
)

wo.add_job(
    'Sleep for Short Period',
    function_sleep_short,
    group='Sleeping',
    cron='*/2 * * * *',
)


def function_random_fail_often():
    if 3 <= random.randint(1,4):
        division_by_zero = 5 / 0
    sleep(4)
    return 'No Error'


def function_random_fail_rare():
    if 1 == random.randint(1,20):
        division_by_zero = 5 / 0
    sleep(4)
    return 'No Error'


wo.add_job(
    'A Function that Fails',
    function_random_fail_often,
    group='Failing',
    cron='*/10 * * * * *',
    retry_attempts=4,
)

wo.add_job(
    'Might Fail Some Times',
    function_random_fail_rare,
    group='Failing',
    cron='* * * * *',
)


def function_full_speed():
    x = int()
    for i in range(99999999):
        x = i * i
    sleep(1)
    return f'Max multiplication result of {x:,}'


wo.add_job(
    'Lower Delay Function',
    function_full_speed,
    group='Rapid Execution',
    cron='* * * * * *',
)


def function_send_worker_information(worker: robit.Worker):
    return f'Worker Success Count: {worker.success_count}'


wo.add_job('Send Worker Information', function_send_worker_information, group='Webhooks Or Database Update', cron='*/30 * * * * *')


if __name__ == '__main__':
    wo.start()

The server will start and host a web portal on default port 8100 locally for you to view what is going on.

Other Libraries Used

  • Boostrap (Responsive UI)
  • Alpine (Better UX)
  • PyTZ (Awesome Time Zone Management)

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

robit-0.4.8.tar.gz (94.8 kB view details)

Uploaded Source

Built Distribution

robit-0.4.8-py3-none-any.whl (107.9 kB view details)

Uploaded Python 3

File details

Details for the file robit-0.4.8.tar.gz.

File metadata

  • Download URL: robit-0.4.8.tar.gz
  • Upload date:
  • Size: 94.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for robit-0.4.8.tar.gz
Algorithm Hash digest
SHA256 076ecf50c32e38b3d854f90ee55861d65ff1f82334762bf21d9e4297701c371e
MD5 b228e4492fb7b0870415aeca81bead25
BLAKE2b-256 5a1d99a4c967b3df0c302a2e6e77ec8742a4cbd1e9c003694ac09ecb49d713d5

See more details on using hashes here.

File details

Details for the file robit-0.4.8-py3-none-any.whl.

File metadata

  • Download URL: robit-0.4.8-py3-none-any.whl
  • Upload date:
  • Size: 107.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for robit-0.4.8-py3-none-any.whl
Algorithm Hash digest
SHA256 7372fd8f1b9c8a082e96221493125a3a8178e7707a912fc5c32c08a414a0766b
MD5 71968d316ee155ef34177991204f1e0b
BLAKE2b-256 be198d044f6d06433572ce039862e092c6980bc250e7dc0f8f23fdf13547c715

See more details on using hashes here.

Supported by

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