Skip to content

An NinjaSphere application that looks after timed actions on the local cloud.

License

Notifications You must be signed in to change notification settings

froz/app-scheduler

 
 

Repository files navigation

NAME

app-scheduler

DESCRIPTION

app-scheduler is an application that manages the scheduled execution of tasks. A task delays until its 'after' event occurs, executes its 'open' actions, delays until the 'before' event occurs, then executes the 'close' actions. If the 'after' and 'before' events are both recurring events, then repeats the cycle again, otherwise the task ends.

'after' and 'before' events can be specified with different kinds of event generation rules. The following rules exist:

timestamp
Specifies an absolute timestamp which can occur at most once.
time-of-day
Specifies a time of day that will recur once each day.
delay
Specifies a delay after the previous event. In the case of a 'after' event this delay will be measured from the start of the task (for the first iteration of the task loop) or from the last 'before' event otherwise. In the case of an 'before' event, this delay will be measured from the time of the last 'after' event.
sunset
Specifies sunset in the local time zone.
sunrise
Specifies sunrise in the local time zone.
dawn
Specifies civil dawn (sun 6 degrees below horizon) in the local time zone.
dusk
Specifies civil dusk (sun 6 degrees below horizon) in the local time zone.

The schedule is passed to the application on startup as its configuration object. The schedule looks like this:

{
    "schedule": [
        {
            "id": "ed9f4064-4f2a-4d1a-8583-c05f19af0b58",
            "description": "Turn on lounge lights for 30 minutes at 19:00",
            "window": {
                "after": {
                    "rule": "time-of-day",
                    "param": "19:00:00"
                },
                "before": {
                    "rule": "delay",
                    "param": "00:30:00"
                }
            },
            "open": [
                {
                    "type": "thing-action",
                    "thingID": "ed9f4064",
                    "action": "turnOn"
                }
            ],
            "close": [
                {
                    "type": "thing-action",
                    "thingID": "ed9f4064",
                    "action": "turnOff"
                }
            ]
        }
    ]
}

A command line utility, nscheduler, can be used to schedule and cancel individual tasks. For example, the task with the above definition would be generated with a nscheduler invocation that looked like this:

nscheduler \
	   --after time-of-day 19:00:00 \
	   --before delay 00:30:00 \
	   --on-open turnOn \
	   --on-close turnOff \
	   --thing ed9f4064 \
	   -- schedule

For more details about the nscheduler command, run nscheduler without any arguments to read some help text.

TOPICS

The scheduler service listens on a topic called:

$site/{siteId}/service/scheduler

It supports the following methods:

schedule {task-model}
cancel {task-id}

About

An NinjaSphere application that looks after timed actions on the local cloud.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 61.0%
  • JavaScript 26.8%
  • CSS 8.1%
  • HTML 2.8%
  • Other 1.3%