Giter Club home page Giter Club logo

leader_cron's Introduction

leader_cron

leader_cron provides a distributed task scheduler for executing task periodically in an Erlang cluster

Participating members of the cluster elect a leader node. The leader node schedules and executes given tasks as per their schedules. Should the leader node become unavailable a new leader is elected who resumes task execution responsibilities.

Tasks are defined by specifying a function in a particular module with given arguments to run according to a schedule. The schedule types are:

  • sleeper - sleep a specified number of milliseconds between task executions
  • one shot - execute task once at a given date and time or after a number of milliseconds
  • cron - define a schedule very similar to Unix cron

Usage

Startup leader_cron on each participating node (do this on all nodes):

leader_cron:start_link(['[email protected]', '[email protected]']).

Schedule tasks from any node. Here a cron style schedule is defined.

leader_cron:schedule_task({cron, {[5], all, all, all, all}},
                          {io, format, [user, "It is 5 past the hour", []]}).

That's it. In this example the task prints, "It is 5 past the hour" on the leader node at 5 minutes past every hour.

You can also schedule anonymous functions:

F = fun(Device, Format, Args) -> io:format(Device, Format, Args) end,
leader_cron:schedule_task({cron, {[5], all, all, all, all}},
                          {F, [user, "It is 5 past the hour", []]}).

See the leader_cron_task module for full scheduling details (or make doc).

Building

Run make or include as a rebar dependency in your project.

Testing

To run all tests run make check. This runs both the eunit tests as well as the common tests. These can also be run individually via make eunit and make ct.

Static Analysis

Dialyzer

To perform the Dialyzer static analysis of the code run make dialyzer. Run make build_plt once before performing the static analysis to build the plt file required by dialyzer.

Xref

To run the Xref cross reference tool run make xref.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.