gasync

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: GPL-3.0 Imports: 25 Imported by: 1

README

gasync

Framework for fast development of complex workflows

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Event

func Event(name string, handler interface{}, ss ...async.Stmt) async.Event

func SwaggerDoc added in v0.1.4

func SwaggerDoc(host string, wfName string, wf func() async.WorkflowState) (interface{}, error)

Types

type Config

type Config struct {
	GCloudProjectID      string
	GCloudLocationID     string
	GCloudTasksQueueName string
	BasePublicURL        string
	CORS                 bool
	Collection           string
	SignSecret           string
}

type DBWorkflow

type DBWorkflow struct {
	Meta            async.State
	State           interface{} // json body of workflow state
	LockTill        time.Time   // optimistic locking
	Sampling100     bool
	Sampling10000   bool
	Sampling1000000 bool
}

type DBWorkflowLog

type DBWorkflowLog struct {
	Meta         async.State
	State        interface{} // json body of workflow state
	Time         time.Time
	ExecDuration time.Duration
	Input        interface{}
	Output       interface{}
	Callback     *async.CallbackRequest

	Sampling100     bool
	Sampling10000   bool
	Sampling1000000 bool
}

type Empty

type Empty struct {
}

type FirestoreEngine

type FirestoreEngine struct {
	Scheduler  *GTasksScheduler
	DB         *firestore.Client
	Collection string
	Workflows  map[string]func() async.WorkflowState
}

func (FirestoreEngine) Checkpoint

func (fs FirestoreEngine) Checkpoint(ctx context.Context, wf *DBWorkflow, s *async.WorkflowState, cb *async.CallbackRequest, input, output interface{}) func(bool) error

func (FirestoreEngine) Get

func (fs FirestoreEngine) Get(ctx context.Context, id string) (*DBWorkflow, error)

func (FirestoreEngine) HandleCallback

func (fs FirestoreEngine) HandleCallback(ctx context.Context, id string, cb async.CallbackRequest, input interface{}) (interface{}, error)

func (FirestoreEngine) HandleEvent

func (fs FirestoreEngine) HandleEvent(ctx context.Context, id string, name string, input interface{}) (interface{}, error)

func (FirestoreEngine) Lock

func (fs FirestoreEngine) Lock(ctx context.Context, id string) (DBWorkflow, error)

func (FirestoreEngine) Resume

func (fs FirestoreEngine) Resume(ctx context.Context, id string) error

func (FirestoreEngine) ScheduleAndCreate

func (fs FirestoreEngine) ScheduleAndCreate(ctx context.Context, id, name string, state interface{}) error

func (FirestoreEngine) Unlock

func (fs FirestoreEngine) Unlock(ctx context.Context, id string) error

type GTasksScheduler

type GTasksScheduler struct {
	Engine      *FirestoreEngine
	C           *cloudtasks.Service
	Collection  string
	ProjectID   string
	LocationID  string
	QueueName   string
	ResumeURL   string
	CallbackURL string
	Secret      string
}

func (*GTasksScheduler) ResumeHandler

func (mgr *GTasksScheduler) ResumeHandler(w http.ResponseWriter, r *http.Request)

func (*GTasksScheduler) Schedule

func (mgr *GTasksScheduler) Schedule(ctx context.Context, id string) error

in this demo we resume workflows right inside the http handler. we use this scheduler only for redundancy in case resume will fail for some reason in http handler.

func (*GTasksScheduler) Setup

func (*GTasksScheduler) Teardown

func (mgr *GTasksScheduler) Teardown(ctx context.Context, req async.CallbackRequest, handled bool) error

func (*GTasksScheduler) TimeoutHandler

func (mgr *GTasksScheduler) TimeoutHandler(w http.ResponseWriter, r *http.Request)

type GTasksSchedulerData

type GTasksSchedulerData struct {
	ID string
}

type GraphCtx

type GraphCtx struct {
	Parent string
	Prev   []string
	Break  []string
}

type Grapher

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

func (*Grapher) AddEdge

func (g *Grapher) AddEdge(from string, to string)

func (*Grapher) AddEdges

func (g *Grapher) AddEdges(from []string, to string)

func (*Grapher) Dot

func (g *Grapher) Dot(s async.Stmt) string

func (*Grapher) Walk

func (g *Grapher) Walk(s async.Stmt, ctx GraphCtx) GraphCtx

type ReflectEvent

type ReflectEvent struct {
	Handler interface{}
}

This is an example of how to create your custom events

func (*ReflectEvent) Handle

func (h *ReflectEvent) Handle(ctx context.Context, req async.CallbackRequest, input interface{}) (interface{}, error)

code that will be executed when event is received

func (ReflectEvent) InputSchema

func (h ReflectEvent) InputSchema() ([]byte, error)

func (ReflectEvent) MarshalJSON

func (h ReflectEvent) MarshalJSON() ([]byte, error)

func (ReflectEvent) Schemas

func (h ReflectEvent) Schemas() (in *jsonschema.Schema, out *jsonschema.Schema, err error)

func (*ReflectEvent) Setup

when we will start listening for this event - Setup() will be called for us to setup this event on external services

func (*ReflectEvent) Teardown

func (t *ReflectEvent) Teardown(ctx context.Context, req async.CallbackRequest, handled bool) error

when we will stop listening for this event - Teardown() will be called for us to remove this event on external services

type ResumeRequest

type ResumeRequest struct {
	ID        string
	Signature string
}

func (ResumeRequest) HMAC added in v0.1.2

func (req ResumeRequest) HMAC(secret []byte) string

type Server

type Server struct {
	Router    *mux.Router
	Engine    *FirestoreEngine
	Scheduler *GTasksScheduler
}

func NewServer

func NewServer(cfg Config, workflows map[string]func() async.WorkflowState) (*Server, error)

func (Server) SimpleEventHandler

func (s Server) SimpleEventHandler(w http.ResponseWriter, r *http.Request)

Receive event and forward it to workflow engine

func (*Server) Timeout added in v0.1.2

func (s *Server) Timeout(dur time.Duration) *TimeoutHandler

type TimeoutHandler

type TimeoutHandler struct {
	Duration time.Duration
	// contains filtered or unexported fields
}

func (*TimeoutHandler) Handle

func (t *TimeoutHandler) Handle(ctx context.Context, req async.CallbackRequest, input interface{}) (interface{}, error)

func (TimeoutHandler) MarshalJSON

func (s TimeoutHandler) MarshalJSON() ([]byte, error)

func (*TimeoutHandler) Setup

func (*TimeoutHandler) Teardown

func (t *TimeoutHandler) Teardown(ctx context.Context, req async.CallbackRequest, handled bool) error

type TimeoutReq added in v0.1.2

type TimeoutReq struct {
	Req       async.CallbackRequest
	Signature string
}

func (TimeoutReq) HMAC added in v0.1.2

func (req TimeoutReq) HMAC(secret []byte) string

Jump to

Keyboard shortcuts

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