No project description provided
Project description
occasionally
A task scheduler and executioner for python 2.7 and 3+ using only the stdlib
Some environments are constrained, for example, an environment with no internet access. When developing for environments like this, the standard lib is the only tool you have to work with.
This package has two main classes that you will want: ocassionally.tasks.Task
is a container for describing tasks. It takes a callable function (and its args and kwargs), and a frequency function to determine how often it should be called.
The ocassionally.scheduler.Scheduler
class runs these Tasks at their set interval, backed by a priority queue. This queue calls a task when it is time, and reschedules it uses the Task's frequency_function
to determine time until next call.
For example:
from ocasionally.task import Task
from ocassionally.scheduler import Scheduler
from ocasionally.time_helper import after_x_minutes
def clean_db():
# get rid of temp users that are created to trial the app. this is pseudo code
with MyDbConnection() as db:
db.Execute("DELETE FROM users WHERE temp_user = 1 AND logged_out = 1")
db_cleaner = ocassionally.task.Task(clean_db, after_x_mintes(5)) # makes a task that cleans the db every 5 minutes
Scheduler.add_task(db_cleaner) # adds the task to the scheduler
Scheduler.foreground() # start the scheduler running in foreground mode (main thread)
Contributing
Since this package only relies on stdlib functionality, setup is pretty easy. On Linux:
1.) Setup virtual env (virtualenv env
).
2.) Activate virtual env (source env/bin/activate
).
3.) Run ./run_tests.sh
to run the tests and install the package in your virtualenv.
4.) Edit code in the occasionally
folder, and make sure you the tests still pass with ./run_tests.sh
!
5.) Code is documented with the Google python style guide (https://google.github.io/styleguide/pyguide.html) and tests are implemented in pytest.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file occasionally-0.0.2.tar.gz
.
File metadata
- Download URL: occasionally-0.0.2.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.7.0 requests/2.25.1 setuptools/44.1.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/2.7.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69107cd6d65954937cd88cfdde2af8d2a81e63d29857bd01dee0a70c783dc3ba |
|
MD5 | 1a09b2321c2e53a8489bb9aaf3d4c9a2 |
|
BLAKE2b-256 | 8dd3374d66e48d784548f08682aa3dcba1a49ace4735e9d9ccd1a1f2347cf575 |
File details
Details for the file occasionally-0.0.2-py2-none-any.whl
.
File metadata
- Download URL: occasionally-0.0.2-py2-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.7.0 requests/2.25.1 setuptools/44.1.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/2.7.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 172bda2324180579d129145aebda480f276dc888521b9891973539ca2cd41675 |
|
MD5 | e9a5681d530c63f762c3840e03697c37 |
|
BLAKE2b-256 | aa42bb50ae45717a9cfc189086bc91aee78de5b138038394cf66995e9b7585cc |