atrigger
A very simple A Trigger JavaScript library that helps you schedule and manage tasks using A Trigger's API.
What is A Trigger?
A Trigger is a tool/service that helps you schedule periodic and fixed-time tasks by sending a GET request to a given url. It is a very simple and considerably flexible alternative to using Cron for job scheduling.
I use it a lot, so I wrote this simple abstraction to make my life easier and hopefully yours too.
Features
This module helps you create, delete, pause, and resume tasks with ease and without worrying about URI Encoding, enormous URIs, GET requests, or anything other than your actual work. Also, with this module you can check if an IP address belongs to an atrigger.com server so you can verify the authenticity of a task call.
This is basically a simple abstraction of the A Trigger Rest API. The main purpose of this mini-project was to create and publish my first npm module as I learn more and more about Node.js and JavaScript. But I didn't want to do something useless, so I built this. :smiley:
Usage Example
atrigger
is very simple to use:
var ATrigger = require('atrigger');
var tasks = new ATrigger({
APIKey: 'API_KEY',
APISecret: 'API_SECRET'
});
tasks.create({
url: 'http://www.krismuniz.com/',
timeSlice: '10min',
count: 10,
tags: {
'title': 'call-my-site',
'id': 'OtftvvsJ'
}
});
You can handle request errors and API responses, too.
tasks.create({
url: 'http://www.krismuniz.com/',
timeSlice: '10min',
count: 10,
}, function(err, res) {
if (err) {
} else {
}
});
Installation
Installing the atrigger
module is as simple as installing any other npm module:
$ npm install atrigger
API Reference
create
method
Creates a new task given a specific set of parameters. The callback function is optional.
tasks.create({
}, callback(err, res));
Required Parameters:
-
url
([string]
): The target url that A Trigger will call at defined timeSlice
. Note: There is no need to use URIEncode(), the module does that for you.
-
timeSlice
([string]
): The time frequency at which your task needs to be executed. (e.g. 'Xminute', 'Xhour', 'Xday', 'Xmonth', 'Xyear'
where X
is a positive integer)
-
tags
([object]
): An object containing tags (e.g. { tagname: tagvalue, tagname2: tagvalue2 }
). You need to tag your tasks for future identification and to control them using the API.
Optional Parameters:
-
retries
([integer]
): How many times A Trigger should try if your server failed (or was down)? Default value: 3
-
count
([integer]
): How many cycles should be repeated? For an infinite amount of times write -1
. Read more at count parameter (Wiki).
-
first
([string from date in ISO 8601 format]
): When should the first call be made? You are not required to set time value by default. Read more at first parameter (Wiki). Hint: use .toISOString()
to convert a date to the proper format.
delete
method
Deletes all tasks containing a specified set of tags. The callback function is optional.
tasks.delete({
}, callback(err, res));
Required Parameters:
tags
([object]
): An object containing tags (e.g. { tagname: tagvalue, tagname2: tagvalue2 }
). You need to tag your tasks for future identification and to control them using the API.
pause
method
Pauses all currently-active tasks that contain a specified set of tags. The callback function is optional.
tasks.pause({
}, callback(err, res));
Required Parameters:
tags
([object]
): An object containing tags (e.g. { tagname: tagvalue, tagname2: tagvalue2 }
). You need to tag your tasks for future identification and to control them using the API.
resume
method
Resumes all currently-paused tasks that contain a specified set of tags. The callback function is optional.
tasks.resume({
}, callback(err, res));
Required Parameters:
tags
([object]
): An object containing tags (e.g. { tagname: tagvalue, tagname2: tagvalue2 }
). You need to tag your tasks for future identification and to control them using the API.
verifyRequest
method
Pass an IP address and the A Trigger API will respond if the call comes from an A Trigger server. The callback function is required (otherwise the method's existence would be pointless).
tasks.verifyRequest({
ip: '192.168.1.1'
}, callback(err, res));
Required Parameters:
ip
([string]
): The IP address you want to verify.
Testing
Want to run some tests?
$ npm install
$ npm test
License
The MIT License (MIT)
Copyright (c) 2015 Kristian Muñiz [http://krismuniz.com/]
Disclaimer
I am not affiliated in any way to A Trigger and this library is not official. I just use this service and wanted to build this library for educational and productivity reasons.