Browse Source

En cours de développement

master
losyme 3 months ago
parent
commit
00ce8297d7
  1. 10
      client/client.go
  2. 48
      client/config.go
  3. 2
      go.mod
  4. 4
      go.sum
  5. 4
      workers/pool.go

10
client/client.go

@ -16,7 +16,7 @@ import (
)
type Client struct {
endpoints *roundrobin.AllList
endpoints *roundrobin.AllLists
logger Logger
}
@ -36,7 +36,7 @@ func (c *Client) CreateJob(job *jw.Job) (*jw.Job, error) {
reqID := job.ID
for _, item := range c.endpoints.Slice() {
for _, item := range c.endpoints.List() {
ep := item.(*endpoint)
if !ep.isReady() {
continue
@ -79,7 +79,7 @@ func (c *Client) CreateJob(job *jw.Job) (*jw.Job, error) {
func (c *Client) NextJob(namespace string) (*jw.Job, error) {
reqID := uuid.New()
for _, item := range c.endpoints.Slice() {
for _, item := range c.endpoints.List() {
ep := item.(*endpoint)
if !ep.isReady() {
continue
@ -123,7 +123,7 @@ func (c *Client) UpdateJob(job *jw.Job) (*jw.Job, error) {
reqID := job.ID
for _, item := range c.endpoints.Slice() {
for _, item := range c.endpoints.List() {
ep := item.(*endpoint)
if !ep.isReady() {
continue
@ -171,7 +171,7 @@ func (c *Client) CreateWorkflow(wf *jw.Workflow) (*jw.Workflow, error) {
reqID := wf.ID
for _, item := range c.endpoints.Slice() {
for _, item := range c.endpoints.List() {
ep := item.(*endpoint)
if !ep.isReady() {
continue

48
client/config.go

@ -20,12 +20,7 @@ import (
"forge.chapril.org/losyme/util"
)
const (
_defaultCtoO = 3
_defaultHOtoC = 1
_defaultOtoHO = 60 * time.Second
_clientTimeout = 10 * time.Second
)
const _clientTimeout = 10 * time.Second
type Endpoint struct {
URL string `cfg:"url"`
@ -211,32 +206,31 @@ func (c *Config) buildTLSCertificate() (*tls.Certificate, error) {
}
func (c *Config) buildBreaker(url string) *breaker.Breaker {
b := breaker.New(_defaultCtoO, _defaultHOtoC, _defaultOtoHO) // @FIXME: config
config := breaker.DefaultConfig() // @FIXME: configigurable ?
if c.Logger != nil {
logger := c.Logger
b.OnStateChange(
func(from, to breaker.State) {
msg := "Endpoint breaker state"
kv := []interface{}{
"url", url,
"from", from,
"to", to,
}
switch to {
case breaker.StateClosed:
logger.Notice(msg, kv...) //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
case breaker.StateHalfOpen:
logger.Warning(msg, kv...) //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
case breaker.StateOpen:
logger.Error(msg, kv...) //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
}
},
)
config.OnStateChange = func(from, to breaker.State) {
msg := "Endpoint breaker state"
kv := []interface{}{
"url", url,
"from", from,
"to", to,
}
switch to {
case breaker.StateClosed:
logger.Notice(msg, kv...) //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
case breaker.StateHalfOpen:
logger.Warning(msg, kv...) //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
case breaker.StateOpen:
logger.Error(msg, kv...) //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
}
}
}
return b
return breaker.New(config)
}
func (c *Config) BuildClient() (*Client, error) {

2
go.mod

@ -4,7 +4,7 @@ go 1.17
require (
forge.chapril.org/dune/jw v0.0.0-20220411164750-0291c24e873b
forge.chapril.org/losyme/breaker v0.0.0-20220409163242-27713f45964f
forge.chapril.org/losyme/breaker v0.0.0-20220411170549-42dd8e90d60f
forge.chapril.org/losyme/errors v0.0.0-20220410175325-24ea6bde8500
forge.chapril.org/losyme/king v0.0.0-20220410175404-85e49de392ff
forge.chapril.org/losyme/kong v0.0.0-20220410175413-680fbdc4fcb4

4
go.sum

@ -1,7 +1,7 @@
forge.chapril.org/dune/jw v0.0.0-20220411164750-0291c24e873b h1:VzxWxzVlAOs8GuAC4t9zHVliGVTsIWVSNT0JePIA7Kc=
forge.chapril.org/dune/jw v0.0.0-20220411164750-0291c24e873b/go.mod h1:eyBPWS4xu8yjh9oqGaJah3kQe+0i/MssMQmnzke1Tf4=
forge.chapril.org/losyme/breaker v0.0.0-20220409163242-27713f45964f h1:Iaa4LfvXwPZwP6rR0z6hIfTSOa1g7T6bhipFBUE0BGA=
forge.chapril.org/losyme/breaker v0.0.0-20220409163242-27713f45964f/go.mod h1:1vBH8Q+vML8EBZj1Pvcpzxx+eEBK+f24QzcXT5Bo+MY=
forge.chapril.org/losyme/breaker v0.0.0-20220411170549-42dd8e90d60f h1:fmwm3agM1q8e+WAF3G3RGsegXnu4RG/DFHIIEYWXXNw=
forge.chapril.org/losyme/breaker v0.0.0-20220411170549-42dd8e90d60f/go.mod h1:1vBH8Q+vML8EBZj1Pvcpzxx+eEBK+f24QzcXT5Bo+MY=
forge.chapril.org/losyme/buffer v0.0.0-20220410175226-b131a708418a h1:3f2hxFLAxRSxa0QZGlk7+3Zvk8hDYfyzBh3Y/qyVXh8=
forge.chapril.org/losyme/buffer v0.0.0-20220410175226-b131a708418a/go.mod h1:4Yl585hmF3bWZfuwGF2Ym8ErykJZiF9yawlmK7szIkc=
forge.chapril.org/losyme/errors v0.0.0-20220410175325-24ea6bde8500 h1:XXxlB1nyPaKsdbV9hnIxapwXcIgmn59X/x4R4pzbgAs=

4
workers/pool.go

@ -22,7 +22,7 @@ type pool struct {
state *state
workers map[string]*worker
stopCh chan bool
zombie *zombie.GWithContext
zombie *zombie.GWContext
}
func newPool(cfg *Config, state *state) *pool {
@ -31,7 +31,7 @@ func newPool(cfg *Config, state *state) *pool {
fqdn = "?"
}
zombie := zombie.NewGWithContext(
zombie := zombie.NewGWContext(
context.Background(),
zombie.WithLogger(cfg.Logger),
)

Loading…
Cancel
Save