Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

ndscheduler: A cron-replacement library from Nextdoor

Project description

# Nextdoor Scheduler

[![Build Status](](

``ndscheduler`` is a flexible python library for building your own cron-like system to schedule jobs, which is to run a tornado process to serve REST APIs and a web ui. It's like [LLVM]( that provides modular and reusable components for building a compiler.

Check out our blog post - [We Don't Run Cron Jobs at Nextdoor](

**``ndscheduler`` currently supports Python 2 & 3 on Mac OS X / Linux.**

## Table of contents

* [Key Abstractions](#key-abstractions)
* [Try it NOW](#try-it-now)
* [How to build Your own cron-replacement](#how-to-build-your-own-cron-replacement)
* [Install ndscheduler](#install-ndscheduler)
* [Three things](#three-things)
* [Reference Implementation](#reference-implementation)
* [Contribute code to ndscheduler](#contribute-code-to-ndscheduler)
* [REST APIs](#rest-apis)
* [Web UI](#web-ui)

## Key Abstractions

* [Core]( a bunch of resuable components
* [Datastore]( manages database connections and makes queries; could support Postgres, MySQL, and sqlite.
* Job: represents a schedule job and decides how to run a paricular job.
* Execution: represents an instance of job execution.
* AuditLog: logs when and who runs what job.
* [ScheduleManager]( access Datastore to manage jobs, i.e., schedule/modify/delete/pause/resume a job.
* [Server]( a tornado server that runs ScheduleManager and provides REST APIs and serves UI.
* [Web UI]( a single page HTML app; this is a default implementation.

## Try it NOW

From source code:

git clone
cd ndscheduler
make simple

Or use docker:

docker run -it -p 8888:8888 wenbinf/ndscheduler

Open your browser and go to [localhost:8888](http://localhost:8888).

(Click for fullscreen play)
![ndscheduler demo](

## How to build Your own cron-replacement

### Install ndscheduler
Using pip (from GitHub repo)

# Put this in requirements.txt, then run
# pip install -r requirements.txt

# If you want the latest build

# Or put this if you want a specific commit

# Or put this if you want a specific tag version

# Run from command line

pip install -e git+

(We'll upload the package to PyPI soon.)

### Three things

You have to implement three things for your scheduler, i.e., ``Settings``, ``Server``, and ``Jobs``.


In your implementation, you need to provide a settings file to override default settings (e.g., [settings in simple_scheduler]( You need to specify the python import path in the environment variable ``NDSCHEDULER_SETTINGS_MODULE`` before running the server.

All available settings can be found in []( file.


You need to have a server file to import and run ``ndscheduler.server.server.SchedulerServer``.


Each job should be a standalone class that is a subclass of ``ndscheduler.job.JobBase`` and put the main logic of the job in ``run()`` function.

After you set up ``Settings``, ``Server`` and ``Jobs``, you can run the whole thing like this:

NDSCHEDULER_SETTINGS_MODULE=simple_scheduler.settings \
python simple_scheduler/

### Reference Implementation

See code in the [simple_scheduler/]( directory for inspiration :)

Run it

make simple

Access the web ui via [localhost:8888](http://localhost:8888)

The reference implementation also comes with [several sample jobs](
* AwesomeJob: it just prints out 2 arguments you pass in.
* SlackJob: it sends a slack message periodically, for example, team standup reminder.
* ShellJob: it runs an executable command, for example, run curl to crawl web pages.
* CurlJob: it's like running [curl]( periodically.

And it's [dockerized](

## Contribute code to ndscheduler

**Install dependencies**

# Each time we introduce a new dependency in, you have to run this
make install

**Run unit tests**

make test

**Clean everything and start from scratch**

make clean

Finally, send pull request. Please make sure the [CI]( passes for your PR.


Please see [ in ndscheduler/server/handlers](

## Web UI

We provide a default implementation of web ui. You can replace the default web ui by overwriting these settings

STATIC_DIR_PATH = :static asset directory paths:
TEMPLATE_DIR_PATH = :template directory path:
APP_INDEX_PAGE = :the file name of the single page app's html:

### The default web ui

**List of jobs**

![List of jobs](

**List of executions**

![List of executions](

**Audit Logs**

![Audit logs](

**Modify a job**

![Modify a job](

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ndscheduler, version 0.3.0
Filename, size File type Python version Upload date Hashes
Filename, size ndscheduler-0.3.0-py2.py3-none-any.whl (369.2 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size ndscheduler-0.3.0-py3.6.egg (414.2 kB) File type Egg Python version 3.6 Upload date Hashes View
Filename, size ndscheduler-0.3.0.tar.gz (325.2 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page