Skip to main content

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.

  • id is always non-null.
  • If id=None, a UUID string is generated.
  • description is optional and may be None.
  • 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 duration is provided with start_time, then end_time = start_time + duration.
  • If end_time is provided with start_time, then duration = 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:

  • id
  • description
  • start_time
  • end_time
  • duration

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. If ts is equal in value to the current list, it is ignored.
  • stop(): requests scheduler stop and clears current time-series state.

Public exports

  • MiniSchedule
  • MiniScheduler
  • FutureCallback
  • SchedulePoint
  • SchedulerControl

Build and publish to PyPI

  1. Build distribution artifacts:
python3 -m pip install --upgrade build twine
python3 -m build
  1. Validate artifacts:
python3 -m twine check dist/*
  1. Upload to TestPyPI first (recommended):
python3 -m twine upload --repository testpypi dist/*
  1. Upload to PyPI:
python3 -m twine upload dist/*
  1. Install from PyPI:
pip install nucore-mini-scheduler

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

nucore_mini_scheduler-0.1.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nucore_mini_scheduler-0.1.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

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

Hashes for nucore_mini_scheduler-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0ba63e333185c1e8065929a057c82ec8d9cf721444e5a297dd3fb3694ef09ab4
MD5 69836cb0c3b5786d173205815f15fa8d
BLAKE2b-256 e2b9bff67cefcd4de8f139495536e0d5fed25aef79a90cbde54c51ea55c7c1a9

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nucore_mini_scheduler-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for nucore_mini_scheduler-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7f7d51500b9181fb8937ca8b19dddc76932c8cd18b7f49ec2a123c04b5039cd0
MD5 dd2af2ade288622c39a0afb2138a3d15
BLAKE2b-256 0bff1a9279dadb2fabcee4fcc1840ebec18213f75acc93315f58d3c1753a1d0b

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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