service

package
v0.0.0-...-d1034c5 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2016 License: BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package service is boilerplate code for making nexus services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Method

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

type Semaphore

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

func (*Semaphore) Acquire

func (s *Semaphore) Acquire()

func (*Semaphore) Cap

func (s *Semaphore) Cap() int

func (*Semaphore) Free

func (s *Semaphore) Free() int

func (*Semaphore) Release

func (s *Semaphore) Release()

func (*Semaphore) Used

func (s *Semaphore) Used() int

type Service

type Service struct {
	Name             string
	Server           string
	User             string
	Password         string
	Prefix           string
	Pulls            int
	PullTimeout      time.Duration
	MaxThreads       int
	StatsPeriod      time.Duration
	GracefulExitTime time.Duration
	LogLevel         string
	// contains filtered or unexported fields
}

func (*Service) AddMethod

func (s *Service) AddMethod(name string, f func(*nexus.Task) (interface{}, *nexus.JsonRpcErr))

AddMethod adds (or replaces if already added) a method for the service The function that receives the nexus.Task should return a result or an error

func (*Service) AddMethodSchema

func (s *Service) AddMethodSchema(name string, schema string, f func(*nexus.Task) (interface{}, *nexus.JsonRpcErr))

AddSchemaMethod adds (or replaces if already added) a method for the service with a JSON schema The function that receives the nexus.Task should return a result or an error If the schema validation does not succeed, an ErrInvalidParams error will be sent as a result for the task

func (*Service) GetConn

func (s *Service) GetConn() *nexus.NexusConn

GetConn returns the underlying nexus connection

func (*Service) GetMethods

func (s *Service) GetMethods() []string

GetMethods returns a list of the methods the service has It returns nil if using a handler

func (*Service) GetStats

func (s *Service) GetStats() *Stats

GetStats returns the service stats

func (*Service) GracefulStop

func (s *Service) GracefulStop()

GracefulStop stops pulling tasks, tries to finish working tasks and then cancels nexus connection (with a timeout)

func (*Service) Serve

func (s *Service) Serve() error

Serves connects to nexus, logins, and launches configured TaskPulls.

func (*Service) SetConn

func (s *Service) SetConn(nc *nexus.NexusConn)

SetConn sets the underlying nexus connection. Once SetConn is called, service url, user and password are ignored and the provided connection is used on serve.

func (*Service) SetGracefulExitTime

func (s *Service) SetGracefulExitTime(t time.Duration)

SetGratefulExitTime sets the gracefull waiting time after a call to StopGraceful() is done

func (*Service) SetHandler

func (s *Service) SetHandler(h func(*nexus.Task) (interface{}, *nexus.JsonRpcErr))

SetHandler sets the task handler for all methods, to allow custom parsing of the method When a handler is set, methods added with AddMethod() have no effect Passing a nil will remove the handler and turn back to methods from AddMethod()

func (*Service) SetLogLevel

func (s *Service) SetLogLevel(t string)

SetLogLevel sets the log level

func (*Service) SetMaxThreads

func (s *Service) SetMaxThreads(maxThreads int)

SetMaxThreads modifies the number of maximum concurrent goroutines resolving nexus.Task

func (*Service) SetPass

func (s *Service) SetPass(pass string)

SetPass modifies the service pass

func (*Service) SetPrefix

func (s *Service) SetPrefix(prefix string)

SetPrefix modifies the service prefix

func (*Service) SetPullTimeout

func (s *Service) SetPullTimeout(t time.Duration)

SetPullTimeout modifies the time to wait for a nexus.Task for each nexus.TaskPull call

func (*Service) SetPulls

func (s *Service) SetPulls(pulls int)

SetPulls modifies the number of concurrent nexus.TaskPull calls

func (*Service) SetStatsPeriod

func (s *Service) SetStatsPeriod(t time.Duration)

SetStatsPeriod changes the period for the stats to be printed

func (*Service) SetUrl

func (s *Service) SetUrl(url string)

SetUrl modifies the service url

func (*Service) SetUser

func (s *Service) SetUser(user string)

SetUser modifies the service user

func (*Service) Stop

func (s *Service) Stop()

Stop cancels nexus connection, cancelling all tasks and stops serving

func (*Service) String

func (s *Service) String() string

String returns some service info as a stirng

type Stats

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

Jump to

Keyboard shortcuts

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