{"modulePath":"github.com/GoPlugin/pluginV2","version":"v0.5.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package services\n\nPackage services contain the key components of the Chainlink node. This includes the Application, JobRunner, LogListener, and Scheduler.\n\n### Application {#hdr-Application}\n\nThe Application is the main component used for starting and stopping the Chainlink node.\n\n### JobRunner {#hdr-JobRunner}\n\nThe JobRunner keeps track of Runs within a Job and ensures that they're executed in order. Within each Run, the tasks are also executed from the JobRunner.\n\n### JobSubscriber {#hdr-JobSubscriber}\n\nThe JobSubscriber coordinates running job events with the EventLog in the Store, and also subscribes to the given address on the Ethereum blockchain.\n\n### Scheduler {#hdr-Scheduler}\n\nThe Scheduler ensures that recurring events are executed according to their schedule, and one-time events occur only when the specified time has passed.\n\n## Types\n\n```go\ntype CheckFunc func() (unwell bool, meta Meta)\n```\n\n```go\ntype Checkable interface {\n\t// Ready should return nil if ready, or an error message otherwise.\n\tReady() error\n\t// Healthy should return nil if healthy, or an error message otherwise.\n\tHealthy() error\n\t// HealthReport returns a full health report of the callee including it's dependencies.\n\t// key is the dep name, value is nil if healthy, or error message otherwise.\n\tHealthReport() map[string]error\n}\n```\nCheckable should be implemented by any type requiring health checks. From the k8s docs: \u003e ready means it’s initialized and healthy means that it can accept traffic in kubernetes See: [https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/)\n\n```go\ntype Checker interface {\n\t// Register a service for health checks.\n\tRegister(name string, service Checkable) error\n\t// Unregister a service.\n\tUnregister(name string) error\n\t// IsReady returns the current readiness of the system.\n\t// A system is considered ready if all checks are passing (no errors)\n\tIsReady() (ready bool, errors map[string]error)\n\t// IsHealthy returns the current health of the system.\n\t// A system is considered healthy if all checks are passing (no errors)\n\tIsHealthy() (healthy bool, errors map[string]error)\n\n\tStart() error\n\tClose() error\n}\n```\nChecker provides a service which can be probed for system health.\n\n```go\nfunc NewChecker() Checker\n```\n\n```go\ntype Config interface {\n\tAutoPprofProfileRoot() string\n\tAutoPprofPollInterval() models.Duration\n\tAutoPprofGatherDuration() models.Duration\n\tAutoPprofGatherTraceDuration() models.Duration\n\tAutoPprofMaxProfileSize() utils.FileSize\n\tAutoPprofCPUProfileRate() int\n\tAutoPprofMemProfileRate() int\n\tAutoPprofBlockProfileRate() int\n\tAutoPprofMutexProfileFraction() int\n\tAutoPprofMemThreshold() utils.FileSize\n\tAutoPprofGoroutineThreshold() int\n}\n```\n\n```go\ntype Meta map[string]interface{}\n```\n\n```go\ntype MultiClose []io.Closer\n```\nMultiClose is a utility for closing multiple services concurrently.\n\n```go\nfunc (m MultiClose) Close() (err error)\n```\nClose closes alls service concurrently and collects any returned errors as a multierr.\n\n```go\ntype MultiStart struct {\n\t// contains filtered or unexported fields\n}\n```\nMultiStart is a utility for starting multiple services together. The set of started services is tracked internally, so that they can be closed if any single service fails to start.\n\n```go\nfunc (m *MultiStart) Close() (err error)\n```\nClose closes all started services, in reverse order.\n\n```go\nfunc (m *MultiStart) CloseBecause(reason error) (err error)\n```\nCloseBecause calls Close and returns reason along with any additional errors.\n\n```go\nfunc (m *MultiStart) Start(ctx context.Context, srvcs ...StartClose) (err error)\n```\nStart attempts to Start all services. If any service fails to start, the previously started services will be Closed, and an error returned.\n\n```go\ntype Nurse struct {\n\tutils.StartStopOnce\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewNurse(cfg Config, log logger.Logger) *Nurse\n```\n\n```go\nfunc (n *Nurse) AddCheck(reason string, checkFunc CheckFunc)\n```\n\n```go\nfunc (n *Nurse) Close() error\n```\n\n```go\nfunc (n *Nurse) GatherVitals(reason string, meta Meta)\n```\n\n```go\nfunc (n *Nurse) Start() error\n```\n\n```go\ntype ServiceCtx interface {\n\t// Start the service. Must quit immediately if the context is cancelled.\n\t// The given context applies to Start function only and must not be retained.\n\tStart(context.Context) error\n\t// Close stops the Service.\n\t// Invariants: Usually after this call the Service cannot be started\n\t// again, you need to build a new Service to do so.\n\tClose() error\n\n\t// Name returns the fully qualified name of the service\n\tName() string\n\n\tCheckable\n}\n```\nServiceCtx represents a long-running service inside the Application.\n\nTypically, a ServiceCtx will leverage utils.StartStopOnce to implement these calls in a safe manner.\n\n### Template {#hdr-Template}\n\nMockable Foo service with a run loop\n\n\t//go:generate mockery --quiet --name Foo --output ../internal/mocks/ --case=underscore\n\ttype (\n\t\t// Expose a public interface so we can mock the service.\n\t\tFoo interface {\n\t\t\tservice.ServiceCtx\n\n\t\t\t// ...\n\t\t}\n\n\t\tfoo struct {\n\t\t\t// ...\n\n\t\t\tstop chan struct{}\n\t\t\tdone chan struct{}\n\n\t\t\tutils.StartStopOnce\n\t\t}\n\t)\n\n\tvar _ Foo = (*foo)(nil)\n\n\tfunc NewFoo() Foo {\n\t\tf := \u0026foo{\n\t\t\t// ...\n\t\t}\n\n\t\treturn f\n\t}\n\n\tfunc (f *foo) Start(ctx context.Context) error {\n\t\treturn f.StartOnce(\"Foo\", func() error {\n\t\t\tgo f.run()\n\n\t\t\treturn nil\n\t\t})\n\t}\n\n\tfunc (f *foo) Close() error {\n\t\treturn f.StopOnce(\"Foo\", func() error {\n\t\t\t// trigger goroutine cleanup\n\t\t\tclose(f.stop)\n\t\t\t// wait for cleanup to complete\n\t\t\t\u003c-f.done\n\t\t\treturn nil\n\t\t})\n\t}\n\n\tfunc (f *foo) run() {\n\t\t// signal cleanup completion\n\t\tdefer close(f.done)\n\n\t\tfor {\n\t\t\tselect {\n\t\t\t// ...\n\t\t\tcase \u003c-f.stop:\n\t\t\t\t// stop the routine\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t}\n\n```go\ntype StartClose interface {\n\tStart(context.Context) error\n\tClose() error\n}\n```\nStartClose is a subset of the ServiceCtx interface.\n\n```go\ntype State struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\ntype Status string\n```\n\n```go\nconst (\n\tStatusPassing Status = \"passing\"\n\tStatusFailing Status = \"failing\"\n)\n```\n\n","path":"github.com/GoPlugin/pluginV2/core/services","name":"services","synopsis":"Package services contain the key components of the Chainlink node.","isRedistributable":true}
