Skip to main content

systemd/cron alternative for python virtualenv

Project description

startme

startme is systemd/cron alternative for python virtualenv

Problem and solution

Sometimes python application is complex and modular. For example, you may have:

  • wsgi web application
  • telegram bot
  • some database maintenance
  • send marketing emails
  • ... and more and more

Some of these modules are optional. How to install it (say, telegram bot)? You may install it with pip, but then you need to activate it - edit systemd .service file and install it. Or, for cron jobs, you need to manually add cron job. This makes module installation more complex, long and vulnerable to mistakes.

Startme looks for subclasses of StartMe class and executes it.

Usage

# create virtualenv
pipenv shell

# install startme
pipenv install startme

# Now lets run it. Not very impressive.
(x) xenon@braconnier:/tmp/x$ startme 
startme started
(x) xenon@braconnier:/tmp/x$ 

# Now install example plugin
pipenv install startme-examples

# run again...
(x) xenon@braconnier:/tmp/x$ startme 
StartMeExampleBoot started
startme started
00:20:25 Ticker tick 10
00:20:35 Ticker tick 10
00:20:45 Ticker tick 10
00:20:55 Ticker tick 10
00:21:05 Ticker tick 10
00:21:15 Ticker1min tick 60
00:21:15 Ticker tick 10
00:21:25 Ticker tick 10

startme-examples has three very simple classes, inherited from StartMe. StartMeExampleBoot - wants to be executed once on start. Ticker wants to be executed every 10 seconds and Ticker1min wants to be executed every 1 minute.

Look startme-examples sources as documentation, it's very small. For example, StartMeExampleBoot is just one class with one method with just one line of code.

from startme import StartMe

class StartMeExampleBoot(StartMe):
    def on_start(self):
        print(self.__class__.__name__, "started")

All StartMe subclasses are automatically detected, loaded and executed. No need for systemd or cron inside virtualenv.

Advanced usage

Startme uses interruptable lightsleep so you can trigger immediate execution of cron tasks.

# Session 1, start startme
$ startme --hook redis
...

# Session 2, redis-cli
$ redis-cli publish sleep Ticker1min
$ redis-cli publish sleep Ticker1min
$ redis-cli publish sleep Ticker1min

# Session 1 again, Ticker1min triggered
00:06:28 Ticker1min tick 60
00:06:28 Ticker1min tick 60
00:06:28 Ticker1min tick 60

Install

pip3 install startme or pipenv install startme or pip3 install git+https://github.com/yaroslaff/startme.

Add to systemd

Use your project name instead of test:

startme --systemd test | sudo tee /etc/systemd/system/startme-test.service
sudo systemctl daemon-reload 
sudo systemctl enable startme-test.service
sudo systemctl start startme-test.service

You may add lightsleep hook parametes to environment file /etc/default

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

startme-0.0.7-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file startme-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: startme-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.2

File hashes

Hashes for startme-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 e3ae2618556a9296a2cb5fda4aeaff048bb285d68daceace8a6982b5ac26f814
MD5 05ccdad8a47a3ebb285fda67ad551ba1
BLAKE2b-256 c5353d22f9b05a44f7bf55faff2ac743328a13278824dd55d5213cda4efe9ae3

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