hooky

module
v0.0.0-...-6ed339e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2015 License: MPL-2.0

README

Hooky

Hooky is a RESTful microservice to manage asynchronous tasks in the cloud.

It uses WebHooks to trigger tasks that can be executed immediately or at a regular interval.

Hooky offers similar services as:

  • Google Cloud Task Queue (push mode)
  • Google Cloud Scheduled Tasks
  • Microsoft Azure Scheduler

Install

Hooky uses MongoDB as its storage backend, by default it expects MongoDB to be running on localhost and will listen on HTTP port 8000.

$ go get github.com/sebest/hooky/cmd/hookyd
$ hookyd

Features

  • RESTful API
  • Asynchronous tasks using Webhooks
  • Tasks can be scheduled with recurrency using a CRON syntax
  • Configurable retry policy
  • Multi-accounts and multi-applications
  • Concurrency limit per Queue
  • Stats per Task
  • Clean finished attempts
  • Stats per Queue
  • Stats per Application
  • Crontabs
  • Delayed Tasks
  • Full documentation
  • Tests

RESTful API

The full API specification is here using the Swagger specification version 2.0.

You can visualize it here.

Tutorial

For this tutorial we will use httpie.

Hooky uses basic authentication, there is a default admin account with a default password that you use to create new accounts.

The default admin password is admin.

Create a new account
$ http -v -a admin:admin POST :8000/accounts
POST /accounts HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Authorization: Basic YWRtaW46YWRtaW4=
Connection: keep-alive
Content-Length: 0
Host: localhost:8000
User-Agent: HTTPie/0.9.2



HTTP/1.1 200 OK
Content-Length: 120
Content-Type: application/json
Date: Sun, 17 May 2015 00:24:30 GMT
X-Powered-By: go-json-rest

{
    "created": "2015-05-17T00:24:30Z",
    "id": "5557dd8eef015fb521000009",
    "key": "Ci6wgzetYviXHhJME6KvyNqkRCZjFBoe"
}

You now have an account id and key to connect to the service. When a new account is created a default application is automatically created for convenience.

Create a new task

Using our new account we can now create a task, the only required parameter is url.

$ http -v -a 5557dd8eef015fb521000009:Ci6wgzetYviXHhJME6KvyNqkRCZjFBoe POST :8000/accounts/5557dd8eef015fb521000009/applications/default/tasks url=http://www.perdu.com
POST /accounts/5557dd8eef015fb521000009/applications/default/tasks HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate
Authorization: Basic NTU1N2RkOGVlZjAxNWZiNTIxMDAwMDA5OkNpNndnemV0WXZpWEhoSk1FNkt2eU5xa1JDWmpGQm9l
Connection: keep-alive
Content-Length: 31
Content-Type: application/json
Host: localhost:8000
User-Agent: HTTPie/0.9.2

{
    "url": "http://www.perdu.com"
}

HTTP/1.1 200 OK
Content-Length: 545
Content-Type: application/json
Date: Sun, 17 May 2015 00:27:39 GMT
X-Powered-By: go-json-rest

{
    "account": "5557dd8eef015fb521000009",
    "active": true,
    "application": "default",
    "at": "2015-05-17T00:27:39Z",
    "auth": {
        "password": "",
        "username": ""
    },
    "created": "2015-05-17T00:27:39Z",
    "errorRate": 0,
    "errors": 0,
    "executions": 0,
    "id": "5557e07bef015fb521000011",
    "method": "POST",
    "name": "5557e07bef015fb521000011",
    "queue": "default",
    "retry": {
        "attempts": 0,
        "factor": 2,
        "max": 300,
        "maxAttempts": 10,
        "min": 10
    },
    "status": "pending",
    "url": "http://www.perdu.com"
}

Our task is queued and will be executed immediately, as we did not provide a name, the task id is used as the task name.

We can query the status of our task:

$ http -v -a 5557dd8eef015fb521000009:Ci6wgzetYviXHhJME6KvyNqkRCZjFBoe GET :8000/accounts/5557dd8eef015fb521000009/applications/default/tasks/5557e07bef015fb521000011
GET /accounts/5557dd8eef015fb521000009/applications/default/tasks/5557e07bef015fb521000011 HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Authorization: Basic NTU1N2RkOGVlZjAxNWZiNTIxMDAwMDA5OkNpNndnemV0WXZpWEhoSk1FNkt2eU5xa1JDWmpGQm9l
Connection: keep-alive
Host: localhost:8000
User-Agent: HTTPie/0.9.2



HTTP/1.1 200 OK
Content-Length: 593
Content-Type: application/json
Date: Sun, 17 May 2015 00:32:19 GMT
X-Powered-By: go-json-rest

{
    "account": "5557dd8eef015fb521000009",
    "active": false,
    "application": "default",
    "auth": {
        "password": "",
        "username": ""
    },
    "created": "2015-05-17T00:27:39Z",
    "errorRate": 0,
    "errors": 0,
    "executed": "2015-05-17T00:27:40Z",
    "executions": 1,
    "id": "5557e07bef015fb521000011",
    "lastSuccess": "2015-05-17T00:27:40Z",
    "method": "POST",
    "name": "5557e07bef015fb521000011",
    "queue": "default",
    "retry": {
        "attempts": 0,
        "factor": 2,
        "max": 300,
        "maxAttempts": 10,
        "min": 10
    },
    "status": "success",
    "url": "http://www.perdu.com"
}

Every tasks generate attempts, if the task succeed on its first attempt, you will only have one, otherwise you can have up to 10 attempts by default.

You can get the attempts' list:

$ http -v -a 5557dd8eef015fb521000009:Ci6wgzetYviXHhJME6KvyNqkRCZjFBoe GET :8000/accounts/5557dd8eef015fb521000009/applications/default/tasks/5557e07bef015fb521000011/attempts
GET /accounts/5557dd8eef015fb521000009/applications/default/tasks/5557e07bef015fb521000011/attempts HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Authorization: Basic NTU1N2RkOGVlZjAxNWZiNTIxMDAwMDA5OkNpNndnemV0WXZpWEhoSk1FNkt2eU5xa1JDWmpGQm9l
Connection: keep-alive
Host: localhost:8000
User-Agent: HTTPie/0.9.2



HTTP/1.1 200 OK
Content-Length: 593
Content-Type: application/json
Date: Sun, 17 May 2015 00:34:34 GMT
X-Powered-By: go-json-rest

{
    "count": 1,
    "hasMore": false,
    "list": [
        {
            "account": "5557dd8eef015fb521000009",
            "application": "default",
            "auth": {
                "password": "",
                "username": ""
            },
            "created": "2015-05-17T00:27:39Z",
            "id": "5557e07bef015fb521000012",
            "method": "POST",
            "name": "5557e07bef015fb521000011",
            "queue": "default",
            "status": "success",
            "statusCode": 200,
            "statusMessage": "200 OK",
            "taskID": "5557e07bef015fb521000011",
            "url": "http://www.perdu.com"
        }
    ],
    "page": 1,
    "pages": 1,
    "total": 1
}

Directories

Path Synopsis
Godeps
_workspace/src/github.com/ant0ine/go-json-rest/rest
A quick and easy way to setup a RESTful JSON API http://ant0ine.github.io/go-json-rest/ Go-Json-Rest is a thin layer on top of net/http that helps building RESTful JSON APIs easily.
A quick and easy way to setup a RESTful JSON API http://ant0ine.github.io/go-json-rest/ Go-Json-Rest is a thin layer on top of net/http that helps building RESTful JSON APIs easily.
_workspace/src/github.com/ant0ine/go-json-rest/rest/test
Utility functions to help writing tests for a Go-Json-Rest app Go comes with net/http/httptest to help writing test for an http server.
Utility functions to help writing tests for a Go-Json-Rest app Go comes with net/http/httptest to help writing test for an http server.
_workspace/src/github.com/ant0ine/go-json-rest/rest/trie
Special Trie implementation for HTTP routing.
Special Trie implementation for HTTP routing.
_workspace/src/github.com/codegangsta/cli
Package cli provides a minimal framework for creating and organizing command line Go applications.
Package cli provides a minimal framework for creating and organizing command line Go applications.
_workspace/src/github.com/robfig/cron
This library implements a cron spec parser and runner.
This library implements a cron spec parser and runner.
_workspace/src/golang.org/x/net/netutil
Package netutil provides network utility functions, complementing the more common ones in the net package.
Package netutil provides network utility functions, complementing the more common ones in the net package.
_workspace/src/gopkg.in/mgo.v2
Package mgo offers a rich MongoDB driver for Go.
Package mgo offers a rich MongoDB driver for Go.
_workspace/src/gopkg.in/mgo.v2/bson
Package bson is an implementation of the BSON specification for Go: http://bsonspec.org It was created as part of the mgo MongoDB driver for Go, but is standalone and may be used on its own without the driver.
Package bson is an implementation of the BSON specification for Go: http://bsonspec.org It was created as part of the mgo MongoDB driver for Go, but is standalone and may be used on its own without the driver.
_workspace/src/gopkg.in/mgo.v2/internal/scram
Pacakage scram implements a SCRAM-{SHA-1,etc} client per RFC5802.
Pacakage scram implements a SCRAM-{SHA-1,etc} client per RFC5802.
_workspace/src/gopkg.in/mgo.v2/txn
The txn package implements support for multi-document transactions.
The txn package implements support for multi-document transactions.
_workspace/src/gopkg.in/yaml.v2
Package yaml implements YAML support for the Go language.
Package yaml implements YAML support for the Go language.
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL