Compare commits
No commits in common. "main" and "v1.0.0" have entirely different histories.
@ -1,9 +0,0 @@
|
|||||||
|
|
||||||
kind: pipeline
|
|
||||||
type: docker
|
|
||||||
name: "test"
|
|
||||||
steps:
|
|
||||||
- name: test
|
|
||||||
image: harbor.front.kjuulh.io/docker-proxy/library/bash:latest
|
|
||||||
commands:
|
|
||||||
- echo 'Run tests'
|
|
34
builder.go
34
builder.go
@ -1,34 +0,0 @@
|
|||||||
package curre
|
|
||||||
|
|
||||||
import "context"
|
|
||||||
|
|
||||||
type FunctionalComponent struct {
|
|
||||||
InitFunc func(fc *FunctionalComponent, ctx context.Context) error
|
|
||||||
StartFunc func(fc *FunctionalComponent, ctx context.Context) error
|
|
||||||
StopFunc func(fc *FunctionalComponent, ctx context.Context) error
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewFunctionalComponent(
|
|
||||||
fc *FunctionalComponent,
|
|
||||||
) Component {
|
|
||||||
return fc
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fc *FunctionalComponent) Init(ctx context.Context) error {
|
|
||||||
if fc.InitFunc != nil {
|
|
||||||
return fc.InitFunc(fc, ctx)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (fc *FunctionalComponent) Start(ctx context.Context) error {
|
|
||||||
if fc.StartFunc != nil {
|
|
||||||
return fc.StartFunc(fc, ctx)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (fc *FunctionalComponent) Stop(ctx context.Context) error {
|
|
||||||
if fc.StopFunc != nil {
|
|
||||||
return fc.StopFunc(fc, ctx)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
@ -2,6 +2,6 @@ package curre
|
|||||||
|
|
||||||
import "context"
|
import "context"
|
||||||
|
|
||||||
type Stopper interface {
|
type Closer interface {
|
||||||
Stop(ctx context.Context) error
|
Close(ctx context.Context) error
|
||||||
}
|
}
|
||||||
|
@ -3,5 +3,5 @@ package curre
|
|||||||
type Component interface {
|
type Component interface {
|
||||||
Initer
|
Initer
|
||||||
Starter
|
Starter
|
||||||
Stopper
|
Closer
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,6 @@ func (hs *httpServer) Start(ctx context.Context) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (hs *httpServer) Stop(ctx context.Context) error {
|
func (hs *httpServer) Close(ctx context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
53
manager.go
53
manager.go
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -31,37 +30,10 @@ func NewManager() *Manager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ComponentsAreReady struct {
|
func (m *Manager) RunNonBlocking(ctx context.Context) error {
|
||||||
}
|
go m.Run(ctx)
|
||||||
|
|
||||||
type CleanupFunc func(ctx context.Context) error
|
return nil
|
||||||
|
|
||||||
func (m *Manager) RunNonBlocking(ctx context.Context, readyChan chan ComponentsAreReady) (CleanupFunc, error) {
|
|
||||||
go func() error {
|
|
||||||
m.initLifetime()
|
|
||||||
err := m.init(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = m.startBlocking(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
readyChan <- ComponentsAreReady{}
|
|
||||||
|
|
||||||
err = m.wait(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}()
|
|
||||||
|
|
||||||
return func(ctx context.Context) error {
|
|
||||||
return m.shutdown(ctx)
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) Run(ctx context.Context) error {
|
func (m *Manager) Run(ctx context.Context) error {
|
||||||
@ -126,14 +98,6 @@ func (m *Manager) start(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) startBlocking(ctx context.Context) error {
|
|
||||||
for _, c := range m.components {
|
|
||||||
m.startComponent(ctx, c)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Manager) startComponent(ctx context.Context, component Component) {
|
func (m *Manager) startComponent(ctx context.Context, component Component) {
|
||||||
defer func() {
|
defer func() {
|
||||||
err := recover()
|
err := recover()
|
||||||
@ -164,13 +128,8 @@ func (m *Manager) initLifetime() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) wait(ctx context.Context) error {
|
func (m *Manager) wait(ctx context.Context) error {
|
||||||
select {
|
exitCode := <-m.exitChan
|
||||||
case exitCode := <-m.exitChan:
|
m.exitCode = exitCode
|
||||||
m.exitCode = exitCode
|
|
||||||
return nil
|
|
||||||
case <-ctx.Done():
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,7 +139,7 @@ func (m *Manager) shutdown(ctx context.Context) error {
|
|||||||
|
|
||||||
go func(ctx context.Context) {
|
go func(ctx context.Context) {
|
||||||
for _, c := range closers {
|
for _, c := range closers {
|
||||||
c.Stop(ctx)
|
c.Close(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
shutdownChan <- struct{}{}
|
shutdownChan <- struct{}{}
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user