woloski / webtask

Webtasks runner

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Webtasks runner

A simple Webtask runner, it enables code communication between webtasks and Javascript code.

How to run you webtask

# Create your webtask
# Additonally you can create it from url
# and you can pass in `--secret` s, check `wt create --help`
# for more info
wt create  my-webtask.js

#//=> https://webtask.it.auth0.com/api/run/my-container/my-webtask

Then you can invoke my-webtask from Javascript like this

import webtaskRunner from 'webtaskRunner';

const runner = webtaskRunner('my-container');
const myWebtask = runner('my-webtask');

// You can pass in parameters at run time
let params = {
    webtask_no_cache: 1,
    random_param1: "hi",
    random_param2: "super hi",
    ..
    random_paramn: "super hi"
}

// Invoke you webtask
myWebtask(params)
    .then((res) => {
        console.log('SUCCESS!!!', res);
    })
    .catch((err) => {
        console.log('Somethin went wront', err);
    })

Examples

You can check two examples:

  • Send Email: webtask, invocation. Send a email; from, to, subject and message are parameterized.
  • Mongo Insert: webtask, invocation. Insert arbitrary data on a parameterized collection.

Internals

This package is very simple, it uses ES6, Promises and Superagent to abstract from an HTTP POST. POST and JSON payload have been used to you can send arbitrary amount of data to your webtask.

Development

# test it
npm test
# Run the examples
babel-node sendEmail.example.js
babel-node mongoInsert.example.js

About

Webtasks runner

License:MIT License


Languages

Language:JavaScript 100.0%