• Stars
    star
    1,080
  • Rank 42,846 (Top 0.9 %)
  • Language
    Python
  • License
    BSD 2-Clause "Sim...
  • Created over 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A flexible python library for building your own cron-like system, with REST APIs and a Web UI.

Nextdoor Scheduler

Apache 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.

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

  • CoreScheduler: encapsulates all core scheduling functionality, and consists of:
    • 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.

Note: corescheduler can also be used independently within your own service if you use a different Tornado server / Web UI.

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.

Demo (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
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/[email protected]#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). 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 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

Upgrading

It is best practice to backup your database before doing any upgrade. ndscheduler relies on apscheduler to serialize jobs to the database, and while it is usually backwards-compatible (i.e. jobs created with an older version of apscheduler will continue to work after upgrading apscheduler) this is not guaranteed, and it is known that downgrading apscheduler can cause issues. See this PR comment for more details.

Reference Implementation

See code in the simple_scheduler/ directory for inspiration :)

Run it

make simple

Access the web ui via 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 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 passes for your PR.

REST APIs

Please see README.md 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

More Repositories

1

ndkale

Kale is a python task worker library that supports priority queues on Amazon SQS
Python
204
star
2

bender

Bender - Serverless ETL Framework
Java
185
star
3

cspm_evaluation_matrix

Nextdoor's Cloud Security Posture Management (CSPM) Evaluation Matrix
51
star
4

pg-bifrost

PostgreSQL Logical Replication tool into Kinesis, S3 and RabbitMQ
Go
41
star
5

zkwatcher.orig

Service monitoring daemon that registers/deregisters servers in Apache ZooKeeper
Python
37
star
6

kingpin

Deployment Automation Engine
Python
27
star
7

ndserviceregistry

Nextdoor ServiceRegistry Foundational Python Class
Python
26
star
8

git-change

Git command to create and manage Gerrit Code Review changes
Python
22
star
9

puppet_zkwatcher

Puppet library and manifest for use with zk_watcher
Ruby
20
star
10

conductor-open

Continuous Deployment
Go
17
star
11

alphabot

Open source python bot to chat with Slack and other platforms.
Python
14
star
12

gogo

Go Link Shortening Service
Python
10
star
13

NDRefresh

Flexible pull to refresh control for iOS, written in Swift.
Swift
10
star
14

buckle

Bind your command-line toolbelt together
Python
10
star
15

nd_okta_auth

Okta/AWS SAML Authenticator with automatic credential refresh!
Python
8
star
16

helm-set-image-tag-action

Shell
8
star
17

puppet_thycotic

Puppet library for accessing 'secrets' stored in Thycotic's 'Secret Server'
Ruby
8
star
18

corridor

Corridor lets you easily match URLs and extract their values
Swift
5
star
19

puppet-strongswan

Manages StrongSwan on a host with Puppet
Puppet
5
star
20

zkmonitor

Zookeeper Monitoring Daemon
Python
5
star
21

code-crypt

Repository-based application secret Python library (w/ CLI)
Python
4
star
22

drydocker

A simple Phabricator Drydock Host as a Docker Container
Makefile
4
star
23

conda_lockfile

Rust
4
star
24

dutch-boy

A Memory Leak Detector Plugin for Nose
Python
4
star
25

airflow_examples

Python
3
star
26

k8s-charts

Internal Helm Chart Repository
Smarty
3
star
27

tornado_rest_client

Tornado REST Client Framework
Python
3
star
28

NDPhraseParser

A library that allows for formatting strings with context, like Python.
Objective-C
3
star
29

public-ops-tools

Rundeck scripts, etc. that are publicly accessible.
Ruby
2
star
30

docker-registry-cache

An nginx cache to be placed in front of a docker registry
Shell
2
star
31

rollbar-log4j

A Rollbar log4j and log4j2 appender
Java
2
star
32

barrelman

Watch the things that matter to you on Github.
Python
2
star
33

nextdoor-google-tag-manager

Template for implementing Nextdoor Pixel in Google Tag Manager
Smarty
2
star
34

puppet_rightscale

Puppet libraries and modules for interacting with RightScale
Ruby
1
star
35

gradon

Python
1
star
36

nextdoor.github.io

Nextdoor Opensource Projects
Makefile
1
star
37

nd-conda

Shell
1
star
38

konfigenetes

Simple Kubernetes Resource Templating
Python
1
star
39

torus-ae

Go
1
star
40

storage_scripts

Shell
1
star
41

puppet-kibana5

Kibana5 Puppet Module
Puppet
1
star
42

tools-base

Base docker image for tools containers
Dockerfile
1
star
43

shrun

A Circleci-inspired yaml-based command/test runner
Python
1
star