Skip to main content

Class: ImportScheduler

Defined in: src/plugins/core/import-scheduler.ts:167

Import scheduler for periodic preprint imports.

Remarks

Manages scheduled import cycles for plugins that require periodic bulk imports (plugins without search API support).

Features:

  • Configurable per-plugin intervals
  • Prevents overlapping import cycles for the same plugin
  • Tracks import statistics and state
  • Graceful shutdown with cycle completion

Example

Basic usage with LingBuzz and Semantics Archive plugins:

const scheduler = new ImportScheduler({ logger });

scheduler.schedulePlugin({
plugin: lingbuzzPlugin,
intervalMs: 12 * 60 * 60 * 1000, // 12 hours
runOnStart: true,
});

scheduler.schedulePlugin({
plugin: semanticsArchivePlugin,
intervalMs: 12 * 60 * 60 * 1000, // 12 hours
runOnStart: true,
});

// On shutdown
await scheduler.stopAll();

Since

0.1.0

Constructors

new ImportScheduler()

new ImportScheduler(options): ImportScheduler

Defined in: src/plugins/core/import-scheduler.ts:203

Creates a new ImportScheduler.

Parameters

options

ImportSchedulerOptions

Scheduler options including logger

Returns

ImportScheduler

Methods

getAllPluginStates()

getAllPluginStates(): readonly Readonly<ScheduledPluginState>[]

Defined in: src/plugins/core/import-scheduler.ts:405

Gets the state of all scheduled plugins.

Returns

readonly Readonly<ScheduledPluginState>[]

Array of plugin states


getPluginState()

getPluginState(pluginId): null | Readonly<ScheduledPluginState>

Defined in: src/plugins/core/import-scheduler.ts:395

Gets the state of a scheduled plugin.

Parameters

pluginId

string

ID of the plugin

Returns

null | Readonly<ScheduledPluginState>

Plugin state or null if not scheduled


getScheduledPluginIds()

getScheduledPluginIds(): readonly string[]

Defined in: src/plugins/core/import-scheduler.ts:414

Gets the IDs of all scheduled plugins.

Returns

readonly string[]

Array of plugin IDs


isPluginScheduled()

isPluginScheduled(pluginId): boolean

Defined in: src/plugins/core/import-scheduler.ts:424

Checks if a plugin is currently scheduled.

Parameters

pluginId

string

ID of the plugin

Returns

boolean

True if scheduled, false otherwise


schedulePlugin()

schedulePlugin(config): void

Defined in: src/plugins/core/import-scheduler.ts:229

Schedules periodic import cycles for a plugin.

Parameters

config

PluginScheduleConfig

Schedule configuration

Returns

void

Remarks

If the plugin is already scheduled, the existing schedule is replaced. Use unschedulePlugin() first if you need to stop the existing schedule without starting a new one.

Throws

PluginError if the plugin is not a valid ImportingPlugin

Example

scheduler.schedulePlugin({
plugin: lingbuzzPlugin,
intervalMs: 43200000, // 12 hours
runOnStart: true,
timeoutMs: 3600000, // 1 hour timeout
});

stopAll()

stopAll(): Promise<void>

Defined in: src/plugins/core/import-scheduler.ts:341

Stops all scheduled import cycles.

Returns

Promise<void>

Remarks

Clears all interval timers but does not interrupt running cycles. Running cycles will complete naturally.

Call this during application shutdown to ensure clean termination.

Example

// In shutdown handler
process.on('SIGTERM', async () => {
await scheduler.stopAll();
process.exit(0);
});

triggerImportCycle()

triggerImportCycle(pluginId): Promise<ImportCycleResult>

Defined in: src/plugins/core/import-scheduler.ts:441

Manually triggers an import cycle for a scheduled plugin.

Parameters

pluginId

string

ID of the plugin

Returns

Promise<ImportCycleResult>

Result of the import cycle

Remarks

Useful for testing or manual refresh. Does not affect the regular schedule (next scheduled run will still occur on time).

Throws

PluginError if plugin is not scheduled

Throws

PluginError if an import cycle is already running for this plugin


unschedulePlugin()

unschedulePlugin(pluginId): boolean

Defined in: src/plugins/core/import-scheduler.ts:309

Unschedules a plugin's import cycles.

Parameters

pluginId

string

ID of the plugin to unschedule

Returns

boolean

True if the plugin was scheduled and removed, false otherwise

Remarks

Does not interrupt a currently running import cycle. The running cycle will complete but no new cycles will start.