A lightweight thread-based scheduler for start/end/future callbacks
Project description
nucore_mini_scheduler
Mini Scheduler that fires events to callback listeners. It uses start/end times and walks through a sorted timeline.
Installation
# local editable install
pip install -e .
# once published on PyPI
pip install nucore-mini-scheduler
Quick start
from datetime import datetime, timedelta, timezone
from nucore_mini_scheduler import MiniSchedule, MiniScheduler
def on_event(segment: MiniSchedule):
print(
"event",
segment.getId(),
segment.getDescription(),
segment.getStartTime(),
segment.getEndTime(),
"processed=", segment.isProcessed(),
)
scheduler = MiniScheduler()
scheduler.registerCallback(on_event)
start = datetime.now(timezone.utc) + timedelta(seconds=3)
segment = MiniSchedule(
id=None, # auto-generated
description="demo segment",
start_time=start,
duration=10,
)
scheduler.setTimeSeries([segment])
MiniSchedule
Represents one schedulable segment.
idis always non-null.- If
id=None, a UUID string is generated. descriptionis optional and may beNone.- Datetimes are normalized to UTC.
Constructor
MiniSchedule(
start_time: datetime | None = None,
end_time: datetime | None = None,
duration: int | timedelta | None = None,
id: str | None = None,
description: str | None = None,
)
Time rules
- If
durationis provided withstart_time, thenend_time = start_time + duration. - If
end_timeis provided withstart_time, thenduration = end_time - start_time. - Naive datetimes are treated as local time, then converted to UTC.
Equality behavior
MiniSchedule uses value-based equality (__eq__). Two segments are equal if all of the following match:
iddescriptionstart_timeend_timeduration
This is used by MiniScheduler.setTimeSeries(...) to ignore a new list when its content is equal to the current time series.
MiniScheduler
Thread-based scheduler that consumes a list of MiniSchedule and emits callbacks.
Callbacks
registerCallback(callback): callback is invoked around start/end transitions.registerFutureCallback(callback, duration_seconds): callback is invoked for segments that begin within the look-ahead window.
Core methods
setTimeSeries(ts: list[MiniSchedule]): starts the worker thread when needed, stops current run, swaps series, then starts scheduling. Iftsis equal in value to the current list, it is ignored.stop(): requests scheduler stop and clears current time-series state.
Public exports
MiniScheduleMiniSchedulerFutureCallbackSchedulePointSchedulerControl
Build and publish to PyPI
- Build distribution artifacts:
python3 -m pip install --upgrade build twine
python3 -m build
- Validate artifacts:
python3 -m twine check dist/*
- Upload to TestPyPI first (recommended):
python3 -m twine upload --repository testpypi dist/*
- Upload to PyPI:
python3 -m twine upload dist/*
- Install from PyPI:
pip install nucore-mini-scheduler
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nucore_mini_scheduler-0.1.0.tar.gz.
File metadata
- Download URL: nucore_mini_scheduler-0.1.0.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ba63e333185c1e8065929a057c82ec8d9cf721444e5a297dd3fb3694ef09ab4
|
|
| MD5 |
69836cb0c3b5786d173205815f15fa8d
|
|
| BLAKE2b-256 |
e2b9bff67cefcd4de8f139495536e0d5fed25aef79a90cbde54c51ea55c7c1a9
|
Provenance
The following attestation bundles were made for nucore_mini_scheduler-0.1.0.tar.gz:
Publisher:
publish-pypi.yml on NuCoreAI/nucore_mini_scheduler
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nucore_mini_scheduler-0.1.0.tar.gz -
Subject digest:
0ba63e333185c1e8065929a057c82ec8d9cf721444e5a297dd3fb3694ef09ab4 - Sigstore transparency entry: 1694034730
- Sigstore integration time:
-
Permalink:
NuCoreAI/nucore_mini_scheduler@462be8e6f25ecbb57f18ccacabbf97523e11feff -
Branch / Tag:
refs/heads/main - Owner: https://github.com/NuCoreAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@462be8e6f25ecbb57f18ccacabbf97523e11feff -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file nucore_mini_scheduler-0.1.0-py3-none-any.whl.
File metadata
- Download URL: nucore_mini_scheduler-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f7d51500b9181fb8937ca8b19dddc76932c8cd18b7f49ec2a123c04b5039cd0
|
|
| MD5 |
dd2af2ade288622c39a0afb2138a3d15
|
|
| BLAKE2b-256 |
0bff1a9279dadb2fabcee4fcc1840ebec18213f75acc93315f58d3c1753a1d0b
|
Provenance
The following attestation bundles were made for nucore_mini_scheduler-0.1.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on NuCoreAI/nucore_mini_scheduler
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nucore_mini_scheduler-0.1.0-py3-none-any.whl -
Subject digest:
7f7d51500b9181fb8937ca8b19dddc76932c8cd18b7f49ec2a123c04b5039cd0 - Sigstore transparency entry: 1694034770
- Sigstore integration time:
-
Permalink:
NuCoreAI/nucore_mini_scheduler@462be8e6f25ecbb57f18ccacabbf97523e11feff -
Branch / Tag:
refs/heads/main - Owner: https://github.com/NuCoreAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@462be8e6f25ecbb57f18ccacabbf97523e11feff -
Trigger Event:
workflow_dispatch
-
Statement type: