Skip to content

scheduler

diapason.connectors.scheduler

SyncScheduler — background thread for periodic incremental connector syncs.

Registers connectors for timed re-sync and runs them on a configurable interval. Designed to be long-lived (daemon thread) inside a running Diapason server process.

Typical usage::

store = KnowledgeStore(db_path=":memory:")
pipeline = IngestionPipeline(store)
engine = SyncEngine(pipeline)

scheduler = SyncScheduler(engine, interval_seconds=3600)
scheduler.add(gmail_connector)
scheduler.add(slack_connector)
scheduler.start()       # background thread syncs every hour

# Later:
scheduler.stop()

SyncScheduler

Runs incremental sync for all registered connectors on a schedule.

Parameters

sync_engine: The :class:~diapason.connectors.sync_engine.SyncEngine used to drive each connector's sync (handles checkpointing). interval_seconds: How often (in seconds) to sync all connected connectors. Defaults to 3600 (one hour).

add(connector)

Register a connector for scheduled sync.

Parameters

connector: Any :class:~diapason.connectors._stubs.BaseConnector instance. Only connected connectors are synced during each cycle.

run_once()

Sync all connected connectors once (synchronous, non-blocking test helper).

Returns

dict[str, int] Mapping of connector_id → number of new chunks ingested. Only connectors that are currently connected are included.

start()

Start the background sync thread.

The thread is a daemon so it does not prevent process exit. The first sync run occurs after one full interval_seconds wait. Calling :meth:start on an already-running scheduler is a no-op.

stop()

Stop the background sync thread.

Signals the thread to exit and waits up to 5 seconds for it to finish the current sync cycle. Safe to call even when the scheduler is not running.