npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bernierllc/scheduler-service

v1.0.5

Published

Service layer for job scheduling with cron management and queue integration

Readme

@bernierllc/scheduler-service

Service layer for job scheduling with cron management and queue integration

Orchestrates cron scheduling functionality with message queue integration and event publishing. Manages scheduled jobs, handles recurring schedules, and provides scheduling workflow orchestration.

Installation

npm install @bernierllc/scheduler-service

Usage

Basic Usage

import { SchedulerService, JobType, ScheduleType } from '@bernierllc/scheduler-service';

const scheduler = new SchedulerService({
  maxConcurrentJobs: 10,
  defaultTimezone: 'UTC'
});

// Start the scheduler
await scheduler.startScheduler();

// Schedule a one-time content publishing job
const job = await scheduler.scheduleContentPublishing('content-123', {
  type: ScheduleType.ONCE,
  publishAt: new Date('2025-01-01T12:00:00Z')
});

console.log(`Job scheduled: ${job.id}`);

Using the Factory

import { SchedulerServiceFactory } from '@bernierllc/scheduler-service';

// Create a content-optimized scheduler
const contentScheduler = SchedulerServiceFactory.createContentScheduler();

// Create a basic scheduler for simple tasks
const basicScheduler = SchedulerServiceFactory.createBasicScheduler();

// Create a development scheduler with enhanced logging
const devScheduler = SchedulerServiceFactory.createDevelopmentScheduler();

Using Utilities

import { SchedulerUtils, JobType } from '@bernierllc/scheduler-service';

// Create schedule configurations
const oneTime = SchedulerUtils.createOneTimeSchedule(
  new Date('2025-01-01T12:00:00Z'),
  'America/New_York'
);

const daily = SchedulerUtils.createCronSchedule('0 9 * * *'); // Daily at 9 AM

const natural = SchedulerUtils.createNaturalSchedule('every weekday at 2pm');

// Create job configurations
const contentJob = SchedulerUtils.createContentPublishJob(
  'content-456', 
  oneTime,
  ['twitter', 'facebook']
);

const workflowJob = SchedulerUtils.createWorkflowTriggerJob(
  'workflow-789',
  daily,
  { triggerData: 'value' }
);

API Reference

SchedulerService

Configuration Options

interface SchedulerServiceConfig {
  maxConcurrentJobs: number;
  defaultTimezone: string;
  jobRetention: {
    completedJobs: number; // days
    failedJobs: number; // days
  };
  retryDefaults: {
    attempts: number;
    delay: number;
    exponentialBackoff: boolean;
  };
  events: {
    enabled: boolean;
    publishToNeverHub: boolean;
  };
  logging: {
    enabled: boolean;
    level: LogLevel;
  };
}

Core Methods

Job Scheduling
  • scheduleJob(jobConfig: JobConfig): Promise<ScheduledJob>
  • scheduleContentPublishing(contentId: string, schedule: ScheduleConfig): Promise<ScheduledJob>
  • scheduleRecurring(recurringConfig: JobConfig): Promise<ScheduledJob>
Job Management
  • cancelJob(jobId: string): Promise<boolean>
  • pauseJob(jobId: string): Promise<boolean>
  • resumeJob(jobId: string): Promise<boolean>
  • rescheduleJob(jobId: string, newSchedule: ScheduleConfig): Promise<ScheduledJob>
Job Queries
  • getJob(jobId: string): Promise<ScheduledJob | null>
  • listJobs(filters?: JobFilters): Promise<ScheduledJob[]>
  • getUpcomingJobs(timeWindow?: number): Promise<ScheduledJob[]>
Batch Operations
  • scheduleBatch(jobs: JobConfig[]): Promise<BatchScheduleResult>
  • cancelBatch(jobIds: string[]): Promise<BatchOperationResult>
Service Management
  • startScheduler(): Promise<void>
  • stopScheduler(): Promise<void>
  • getSchedulerStatus(): Promise<SchedulerStatus>

Types

JobConfig

interface JobConfig {
  id?: string;
  name: string;
  type: JobType;
  schedule: ScheduleConfig;
  payload: Record<string, any>;
  options?: JobOptions;
}

ScheduleConfig

interface ScheduleConfig {
  type: ScheduleType;
  expression?: string; // Cron or natural language
  publishAt?: Date;
  recurring?: RecurringConfig;
  timezone?: string;
  exceptions?: Date[];
}

Job Types

  • CONTENT_PUBLISH - Content publishing jobs
  • WORKFLOW_TRIGGER - Workflow trigger jobs
  • MAINTENANCE - System maintenance jobs
  • CUSTOM - Custom job types

Schedule Types

  • ONCE - One-time execution
  • RECURRING - Recurring execution with cron
  • NATURAL - Natural language scheduling

Examples

Content Publishing Workflow

import { SchedulerService, SchedulerUtils, JobType } from '@bernierllc/scheduler-service';

const scheduler = new SchedulerService();
await scheduler.startScheduler();

// Schedule immediate publishing
const immediateJob = await scheduler.scheduleContentPublishing('article-123', {
  type: ScheduleType.ONCE,
  publishAt: new Date(Date.now() + 5000) // 5 seconds from now
});

// Schedule recurring social media posts
const socialSchedule = SchedulerUtils.createCronSchedule('0 9,15,21 * * *'); // 3 times daily
const socialJob = await scheduler.scheduleContentPublishing('social-post-456', socialSchedule);

console.log('Jobs scheduled:', { immediateJob: immediateJob.id, socialJob: socialJob.id });

Batch Operations

import { SchedulerUtils, JobType } from '@bernierllc/scheduler-service';

const jobs = [
  SchedulerUtils.createContentPublishJob('content-1', oneTimeSchedule),
  SchedulerUtils.createContentPublishJob('content-2', oneTimeSchedule),
  SchedulerUtils.createContentPublishJob('content-3', oneTimeSchedule)
];

const result = await scheduler.scheduleBatch(jobs);
console.log(`Scheduled ${result.successful.length}/${result.total} jobs`);

if (result.errors.length > 0) {
  console.error('Errors:', result.errors);
}

Job Monitoring

// Get scheduler status
const status = await scheduler.getSchedulerStatus();
console.log(`Scheduler running: ${status.running}, Active jobs: ${status.activeJobs}`);

// List upcoming jobs
const upcoming = await scheduler.getUpcomingJobs(3600000); // Next hour
console.log('Upcoming jobs:', upcoming.map(j => ({ 
  id: j.id, 
  name: j.name, 
  nextRun: j.nextRun 
})));

// Filter jobs by type
const contentJobs = await scheduler.listJobs({ type: JobType.CONTENT_PUBLISH });
console.log(`Content publishing jobs: ${contentJobs.length}`);

Integration with NeverHub

When NeverHub is detected, the scheduler automatically publishes events:

  • job.scheduled - When a job is scheduled
  • job.started - When job execution begins
  • job.completed - When job completes successfully
  • job.failed - When job execution fails
  • scheduler.started - When scheduler starts
  • scheduler.stopped - When scheduler stops

Dependencies

This package orchestrates several BernierLLC core packages:

  • @bernierllc/cron-scheduler - Core cron functionality
  • @bernierllc/schedule-parser - Schedule expression parsing
  • @bernierllc/message-queue - Job queuing
  • @bernierllc/neverhub-adapter - Event publishing (optional)
  • @bernierllc/logger - Logging
  • @bernierllc/retry-manager - Retry logic for failed jobs

See Also

License

Copyright (c) 2025 Bernier LLC. All rights reserved.