Skip to main content
# Nextdoor Scheduler

![Apache](https://img.shields.io/hexpm/l/plug.svg)
[![Build Status](https://travis-ci.org/Nextdoor/ndscheduler.svg)](https://travis-ci.org/Nextdoor/ndscheduler)

``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](http://llvm.org/) that provides modular and reusable components for building a compiler.

Check out our blog post - [We Don't Run Cron Jobs at Nextdoor](https://engblog.nextdoor.com/we-don-t-run-cron-jobs-at-nextdoor-6f7f9cc62040#.d2erw1pl6)

**``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](https://github.com/Nextdoor/ndscheduler/tree/master/ndscheduler/core): a bunch of resuable components
* [Datastore](https://github.com/Nextdoor/ndscheduler/tree/master/ndscheduler/core/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](https://github.com/Nextdoor/ndscheduler/blob/master/ndscheduler/core/scheduler_manager.py): access Datastore to manage jobs, i.e., schedule/modify/delete/pause/resume a job.
* [Server](https://github.com/Nextdoor/ndscheduler/tree/master/ndscheduler/server): a tornado server that runs ScheduleManager and provides REST APIs and serves UI.
* [Web UI](https://github.com/Nextdoor/ndscheduler/tree/master/ndscheduler/static): a single page HTML app; this is a default implementation.

## Try it NOW

From source code:

git clone https://github.com/Nextdoor/ndscheduler.git
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).

**Demo**
(Click for fullscreen play)
![ndscheduler demo](https://giant.gfycat.com/NastyBossyBeaver.gif)

## 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
git+https://github.com/Nextdoor/ndscheduler.git#egg=ndscheduler

# Or put this if you want a specific commit
git+https://github.com/Nextdoor/ndscheduler.git@5843322ebb440d324ca5a66ba55fea1fd00dabe8

# Or put this if you want a specific tag version
git+https://github.com/Nextdoor/ndscheduler.git@v0.1.0#egg=ndscheduler

#
# Run from command line
#

pip install -e git+https://github.com/Nextdoor/ndscheduler.git#egg=ndscheduler

(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``.

**Settings**

In your implementation, you need to provide a settings file to override default settings (e.g., [settings in simple_scheduler](https://github.com/Nextdoor/ndscheduler/blob/master/simple_scheduler/settings.py)). 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 [default_settings.py](https://github.com/Nextdoor/ndscheduler/blob/master/ndscheduler/default_settings.py) file.

**Server**

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

**Jobs**

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 \
PYTHONPATH=.:$(PYTHONPATH) \
python simple_scheduler/scheduler.py

### Reference Implementation

See code in the [simple_scheduler/](https://github.com/Nextdoor/ndscheduler/tree/master/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](https://github.com/Nextdoor/ndscheduler/tree/master/simple_scheduler/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](http://curl.haxx.se/) periodically.

And it's [dockerized](https://github.com/Nextdoor/ndscheduler/tree/master/simple_scheduler/docker).

## Contribute code to ndscheduler

**Install dependencies**

# Each time we introduce a new dependency in setup.py, 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](https://travis-ci.org/Nextdoor/ndscheduler) passes for your PR.

## REST APIs

Please see [README.md in ndscheduler/server/handlers](https://github.com/Nextdoor/ndscheduler/blob/master/ndscheduler/server/handlers/README.md).

## 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](http://i.imgur.com/dGILbkZ.png)

**List of executions**

![List of executions](http://i.imgur.com/JpjzrlU.png)

**Audit Logs**

![Audit logs](http://i.imgur.com/eHLzHhw.png)

**Modify a job**

![Modify a job](http://i.imgur.com/aWv6xOR.png)


Download files

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

Source Distribution

ndscheduler-0.3.0.tar.gz (325.2 kB view details)

Uploaded Source

Built Distributions

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

ndscheduler-0.3.0-py3.6.egg (414.2 kB view details)

Uploaded Egg

ndscheduler-0.3.0-py2.py3-none-any.whl (369.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file ndscheduler-0.3.0.tar.gz.

File metadata

  • Download URL: ndscheduler-0.3.0.tar.gz
  • Upload date:
  • Size: 325.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for ndscheduler-0.3.0.tar.gz
Algorithm Hash digest
SHA256 bd7405fdd398b3f04c308bb9cb962c0ddf34cb6cf7f65c4c89e5cce027983b83
MD5 6d6e53baa91348e689eb33d29b53f355
BLAKE2b-256 372e5c29b00338f6831ac0076f9b38576a8004b7c22f19722afce9a86f91cc4f

See more details on using hashes here.

File details

Details for the file ndscheduler-0.3.0-py3.6.egg.

File metadata

  • Download URL: ndscheduler-0.3.0-py3.6.egg
  • Upload date:
  • Size: 414.2 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for ndscheduler-0.3.0-py3.6.egg
Algorithm Hash digest
SHA256 1e6334b1268673929bf63e77a9ab354ea70e1105a253d40533a27142f674d656
MD5 42423e034dcf2cffa1c8344b208f8eb6
BLAKE2b-256 f8db65f0d67a95d9d95a30d00504d86e26bba10b2095d5d5fca4e7a55599b557

See more details on using hashes here.

File details

Details for the file ndscheduler-0.3.0-py2.py3-none-any.whl.

File metadata

  • Download URL: ndscheduler-0.3.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 369.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for ndscheduler-0.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 69fe97f33cd04a1061a3552da5dabf7e3fe9d58c7d0b89c16a8d6b46a2bcbb36
MD5 697a8bd51414279299a7229ef08ffc02
BLAKE2b-256 a2c32928f0e73589d190da76f45e6316b8c535b83671972dcb945fbd7dc1c5a0

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.3.0 This release

3 files

Supported by

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