Browse Source

En cours de développement

master
losyme 7 months ago
parent
commit
3354ee9f3a
  1. 2
      Taskfile.yml
  2. 14
      client/client.go
  3. 83
      client/config.go
  4. 1
      go.mod
  5. 2
      go.sum
  6. 5
      runner/job.go
  7. 16
      runner/runner.go
  8. 14
      workers/config.go
  9. 2
      workers/worker.go
  10. 9
      workers/workers.go

2
Taskfile.yml

@ -7,7 +7,9 @@ tasks:
update:
cmds:
- go get -u forge.chapril.org/dune/jw
- go get -u forge.chapril.org/losyme/breaker
- go get -u forge.chapril.org/losyme/errors
- go get -u forge.chapril.org/losyme/util
- go get -u forge.chapril.org/losyme/uuid
- go mod tidy
lint:

14
sdk.go → client/client.go

@ -4,16 +4,12 @@
------------------------------------------------------------------------------------------------------------------------
*/
package sdk
package client
type Logger interface {
Trace(msg string, kv ...interface{})
Debug(msg string, kv ...interface{})
Info(msg string, kv ...interface{})
Notice(msg string, kv ...interface{})
Warning(msg string, kv ...interface{})
Error(msg string, kv ...interface{})
Fatal(msg string, kv ...interface{})
type Client struct{}
func New(c *Config) *Client {
return &Client{}
}
/*

83
client/config.go

@ -0,0 +1,83 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### sdk ####### Copyright (c) 2021 losyme ###################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package client
import (
"net/url"
"forge.chapril.org/losyme/errors"
"forge.chapril.org/losyme/util"
)
type Logger interface{}
type Endpoint struct {
URL string
Username string
Password string
CA string
}
type Config struct {
Endpoints []*Endpoint
Cert string
Key string
Logger Logger
}
func (cfg *Config) validate() error {
if cfg.Logger == nil {
return errors.New("the logger cannot be nil") //////////////////////////////////////////////////////////////////
}
if len(cfg.Endpoints) == 0 {
return errors.New("the list of endpoints cannot be empty") /////////////////////////////////////////////////////
}
for _, ep := range cfg.Endpoints {
url, err := url.Parse(ep.URL)
if err != nil || (url.Scheme != "http" && url.Scheme != "https") {
return errors.WithMessage( /////////////////////////////////////////////////////////////////////////////////
err,
"this url is not valid",
"url", ep.URL,
)
}
if ep.CA == "" {
continue
}
if ca, err := util.FileExists(ep.CA); err != nil {
return err
} else if !ca {
return errors.New("this file doesn't exist", "file", ep.CA) ////////////////////////////////////////////////
}
}
if cfg.Cert == "" || cfg.Key == "" {
return nil
}
if cert, err := util.FileExists(cfg.Cert); err != nil {
return err
} else if !cert {
return errors.New("this file doesn't exist", "file", cfg.Cert) /////////////////////////////////////////////////
}
if key, err := util.FileExists(cfg.Key); err != nil {
return err
} else if !key {
return errors.New("this file doesn't exist", "file", cfg.Key) //////////////////////////////////////////////////
}
return nil
}
/*
######################################################################################################## @(°_°)@ #######
*/

1
go.mod

@ -5,6 +5,7 @@ go 1.17
require (
forge.chapril.org/dune/jw v0.0.0-20211205143034-b316149dd167
forge.chapril.org/losyme/errors v0.0.0-20211003204336-ad5510c24b40
forge.chapril.org/losyme/util v0.0.0-20211205153848-3e13eadb49eb
forge.chapril.org/losyme/uuid v0.0.0-20211007082235-8d502169e034
)

2
go.sum

@ -6,5 +6,7 @@ forge.chapril.org/losyme/errors v0.0.0-20211003204336-ad5510c24b40 h1:EoVVFHoIsW
forge.chapril.org/losyme/errors v0.0.0-20211003204336-ad5510c24b40/go.mod h1:saYfIRBW9zjiCik+/+5ZaajMEnTPBNI00lF9EnO+2kM=
forge.chapril.org/losyme/kvfmt v0.0.0-20211003204256-34ac32764dae h1:RdYWXKy+OQNJueb4Qqqo7sL4OY3/TpfUvmoIoH8ua9E=
forge.chapril.org/losyme/kvfmt v0.0.0-20211003204256-34ac32764dae/go.mod h1:wnVjwnCO2vFLLZ1EgFuFws1n8XLluufsGsdozGYSA7c=
forge.chapril.org/losyme/util v0.0.0-20211205153848-3e13eadb49eb h1:zJ8AFh3nkvoLfwqXrRbSgJTqMhYTxdETrzkUFXGLoOM=
forge.chapril.org/losyme/util v0.0.0-20211205153848-3e13eadb49eb/go.mod h1:lKYvkuBOTU3E2HuQZDh4ZSA4u3VcFopQbdPUKaHGHEk=
forge.chapril.org/losyme/uuid v0.0.0-20211007082235-8d502169e034 h1:4NMOPXxwRiXS7wltj2ZZmMO1nFRMPmG1dXK4Ta4MtiM=
forge.chapril.org/losyme/uuid v0.0.0-20211007082235-8d502169e034/go.mod h1:AgvbvGzTkQkbiM+s9eVhvLUSHbA0V6N+q5oBFI2v0LA=

5
runner/job.go

@ -9,17 +9,16 @@ package runner
import (
"forge.chapril.org/dune/jw"
"forge.chapril.org/dune/sdk"
"forge.chapril.org/dune/sdk/factory"
)
type Job struct {
*jw.Job
Logger sdk.Logger
Logger Logger
Factory *factory.Factory
}
func newJob(job *jw.Job, logger sdk.Logger, factory *factory.Factory) *Job {
func newJob(job *jw.Job, logger Logger, factory *factory.Factory) *Job {
return &Job{
Job: job,
Logger: logger,

16
runner/runner.go

@ -13,11 +13,19 @@ import (
"forge.chapril.org/dune/jw"
"forge.chapril.org/losyme/errors"
"forge.chapril.org/dune/sdk"
"forge.chapril.org/dune/sdk/factory"
)
type PanicHandler func(job *jw.Job, logger sdk.Logger, data interface{}, stack []byte)
type Logger interface {
Trace(msg string, kv ...interface{})
Debug(msg string, kv ...interface{})
Info(msg string, kv ...interface{})
Notice(msg string, kv ...interface{})
Warning(msg string, kv ...interface{})
Error(msg string, kv ...interface{})
}
type PanicHandler func(job *jw.Job, logger Logger, data interface{}, stack []byte)
type Runner struct {
namespace string
@ -60,7 +68,7 @@ func (r *Runner) jobHandler(job *jw.Job) JobHandler {
return nil
}
func (r *Runner) runJob(job *jw.Job, logger sdk.Logger) {
func (r *Runner) runJob(job *jw.Job, logger Logger) {
defer func() {
if data := recover(); data != nil {
if r.panicHandler != nil {
@ -85,7 +93,7 @@ func (r *Runner) runJob(job *jw.Job, logger sdk.Logger) {
}
}
func (r *Runner) RunJob(job *jw.Job, logger sdk.Logger) {
func (r *Runner) RunJob(job *jw.Job, logger Logger) {
r.runJob(job, logger)
jr := job.Result

14
workers/config.go

@ -6,15 +6,25 @@
package workers
import "forge.chapril.org/losyme/errors"
import (
"forge.chapril.org/losyme/errors"
)
const _maxPoolSize = 20
type Logger interface {
Clone(id, name string) (Logger, error)
Info(msg string, kv ...interface{})
Warning(msg string, kv ...interface{})
Error(msg string, kv ...interface{})
Remove()
}
type Config struct {
PoolSize int
Host string
Runner Runner
Logger Logger
Runner Runner
}
func (cfg *Config) validate() error {

2
workers/worker.go

@ -90,7 +90,7 @@ func (w *worker) updateJob(job *jw.Job, logger Logger) {
func (w *worker) maybeRunJob() time.Duration {
defer func() {
if data := recover(); data != nil {
w.logger.Fatal("PANIC ERROR RECOVERED", "data", data, "stack", string(debug.Stack())) //::::::::::::::::::::
w.logger.Error("PANIC ERROR RECOVERED", "data", data, "stack", string(debug.Stack())) //::::::::::::::::::::
w.stop()
}
}()

9
workers/workers.go

@ -12,20 +12,13 @@ import (
"forge.chapril.org/dune/jw"
"forge.chapril.org/losyme/errors"
"forge.chapril.org/dune/sdk"
"forge.chapril.org/dune/sdk/runner"
)
type Logger interface {
sdk.Logger
Clone(id, name string) (Logger, error)
Remove()
}
type Runner interface {
Namespace() string
Model() runner.Model
RunJob(job *jw.Job, logger sdk.Logger)
RunJob(job *jw.Job, logger Logger)
}
type Workers struct {

Loading…
Cancel
Save