micro

package module
v1.0.4-0...-8e5595e Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2019 License: MIT Imports: 8 Imported by: 0

README

Micro - the serverless Go functions framework

Godoc

Usage

A simple timer trigger:

import "github.com/openbooking-ch/micro"

func myFunc(payload *string, log *log.Logger) (*string, error) {
    // Run any code here
    // Log output to log interface,
    // will be pushed to console and eventservice, if configured
    //
    // Return *string for Trigger which support returning a result
    // like HTTPTrigger
    // Return err if execution failed. Error will be logged and
    // Triggers can decide how to handle
}

func main() {
    micro.NewTimerTrigger("0 0 12 * * *", myFunc)
    micro.Start()
}
import "github.com/openbooking-ch/micro"

func import(provider string) micro.Func {
  return func (log *log.Logger) {
  }
}

func main() {
	eventservice, err := eventers.NewPGClient(os.Getenv("DATABASE_URL"))
    if err != nil {
        t.Error(err)
    }
    SetEventer(eventservice)
	
    micro.NewTimerTrigger("0 0 12 * * *", import("providerA"), "import")
    micro.NewTimerTrigger("0 0 14 * * *", import("providerB"), "import")
    
	// Start triggers and continue, or...
	micro.Start()
	
	// Start triggers and a HTTP listener
	micro.StartAndListen(os.Getenv("PORT"))
}

Eventservices

Currently, there is one event service logger which supports logging to a Postgres database table. Micro provides the Eventer interface which will allow you to write your own event service loggers.

type Eventer interface {
	PushEvent(class string, startTime, endTime time.Time, output string, err error) error
}

Roadmap

  • Add function chaining
  • Add more trigger types

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Snitch

func Snitch(id string) func(error)

Snitch reports to http://deadmansnitch.com On Error, it sends the errors message along with an error code

Types

type Eventer

type Eventer interface {
	PushEvent(class string, startTime, endTime time.Time, output string, dataIn *string, err error) error
}

type Executor

type Executor struct {
	// contains filtered or unexported fields
}

func (*Executor) AddTrigger

func (e *Executor) AddTrigger(t trigger.Trigger) *Executor

func (*Executor) OnFinish

func (e *Executor) OnFinish(f func(error)) *Executor

type Fn

type Fn func(*log.Logger, *string) (*string, error)

Fn is the core of micro. It's the function that gets executed when a trigger fires. Fn should log output to logger and return error

type Micro

type Micro struct {
	// contains filtered or unexported fields
}

func New

func New() *Micro

func (*Micro) NewExecutor

func (m *Micro) NewExecutor(name string, fn Fn) *Executor

func (*Micro) SetEventer

func (m *Micro) SetEventer(event Eventer)

SetEventer sets an eventservice looger instance

func (*Micro) Start

func (m *Micro) Start()

Start starts the scheduler and returns immediately HTTP Triggers will not work this way (right now)

func (*Micro) StartAndListen

func (m *Micro) StartAndListen(port int)

StartAndListen starts the scheduler and the HTTP listener

func (*Micro) StartAndWait

func (m *Micro) StartAndWait()

StartAndWait starts the scheduler and waits indefinitely Works with Cron, HTTP and SQS Trigger

func (*Micro) StartWithDone

func (m *Micro) StartWithDone() chan interface{}

StartWithDone starts the scheduler and returns a done channel Works with Cron, HTTP and SQS Trigger

func (*Micro) Stop

func (m *Micro) Stop()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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