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

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.6-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: startme-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 5.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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 06a09d7cf042ae9ea008b3d75b96e54575b43a2a6a8ae2808fcff0072c30ba33
MD5 78881c84ce53ca8270b692923eb8debd
BLAKE2b-256 867044752e401fa7e0080589dd0f1f2a0f7e4d6a84f715ad595b1f2b12bb25e5

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