diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..ec54ba0 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +root = true + +[*] +indent_style = space +indent_size = 4 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.go] +indent_style = tab + +[*.md] +trim_trailing_whitespace = false + diff --git a/LICENSE b/LICENSE index 2071b23..5bd6226 100644 --- a/LICENSE +++ b/LICENSE @@ -1,9 +1,19 @@ -MIT License +MIT License Copyright (c) 2021 losyme -Copyright (c) +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 33c22e2..8093b0c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ # sdk -AFAIRE \ No newline at end of file +A FAIRE. + +## Licence + +MIT. + +--- +Copyright (c) 2021 `losyme`. + diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..bf181d7 --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,26 @@ +## https://taskfile.dev +##--------------------- + +version: '3' + +tasks: + update: + cmds: + - go get -u forge.chapril.org/dune/jw + - go mod tidy + lint: + cmds: + - golangci-lint run + test: + cmds: + - go test -cover -v ./... + default: + cmds: + - task: lint + - task: test + git: + cmds: + - git add . + - git commit -m "En cours de développement" + - git push + diff --git a/factory/factory.go b/factory/factory.go new file mode 100644 index 0000000..ec09c75 --- /dev/null +++ b/factory/factory.go @@ -0,0 +1,42 @@ +/* +------------------------------------------------------------------------------------------------------------------------ +####### sdk ####### Copyright (c) 2021 losyme ###################################################### MIT License ####### +------------------------------------------------------------------------------------------------------------------------ +*/ + +package factory + +import "forge.chapril.org/dune/jw" + +type Model interface { + CreateJob(job *jw.Job) (*jw.Job, error) + CreateWorkflow(wf *jw.Workflow) (*jw.Workflow, error) +} + +type Factory struct { + model Model +} + +func New(model Model) *Factory { + return &Factory{ + model: model, + } +} + +func (f *Factory) NewJob(namespace, _type string) *Job { + return &Job{ + job: jw.NewJob(namespace, _type), + model: f.model, + } +} + +func (f *Factory) NewWorkflow(firstStep string, allSteps map[string]*jw.Step) *Workflow { + return &Workflow{ + wf: jw.NewWorkflow(firstStep, allSteps), + model: f.model, + } +} + +/* +######################################################################################################## @(°_°)@ ####### +*/ diff --git a/factory/job.go b/factory/job.go new file mode 100644 index 0000000..05afd2d --- /dev/null +++ b/factory/job.go @@ -0,0 +1,121 @@ +/* +------------------------------------------------------------------------------------------------------------------------ +####### sdk ####### Copyright (c) 2021 losyme ###################################################### MIT License ####### +------------------------------------------------------------------------------------------------------------------------ +*/ + +package factory + +import ( + "time" + + "forge.chapril.org/dune/jw" +) + +type Job struct { + job *jw.Job + model Model +} + +func (job *Job) SetID(value string) *Job { + job.job.SetID(value) + return job +} + +func (job *Job) SetName(value string) *Job { + job.job.SetName(value) + return job +} + +func (job *Job) SetOrigin(value string) *Job { + job.job.SetOrigin(value) + return job +} + +func (job *Job) SetPriority(value jw.Priority) *Job { + job.job.SetPriority(value) + return job +} + +func (job *Job) SetPriorityNone() *Job { + job.job.SetPriorityNone() + return job +} + +func (job *Job) SetPriorityLow() *Job { + job.job.SetPriorityLow() + return job +} + +func (job *Job) SetPriorityMedium() *Job { + job.job.SetPriorityMedium() + return job +} + +func (job *Job) SetPriorityHigh() *Job { + job.job.SetPriorityHigh() + return job +} + +func (job *Job) SetPriorityCritical() *Job { + job.job.SetPriorityCritical() + return job +} + +func (job *Job) SetPublic(key string, value interface{}) *Job { + job.job.SetPublic(key, value) + return job +} + +func (job *Job) SetPrivate(key string, value interface{}) *Job { + job.job.SetPrivate(key, value) + return job +} + +func (job *Job) SetRunAfter(value time.Time) *Job { + job.job.SetRunAfter(value) + return job +} + +func (job *Job) SetExclusivity(value jw.Exclusivity) *Job { + job.job.SetExclusivity(value) + return job +} + +func (job *Job) SetExclusivityNo() *Job { + job.job.SetExclusivityNo() + return job +} + +func (job *Job) SetExclusivityItself() *Job { + job.job.SetExclusivityItself() + return job +} + +func (job *Job) SetExclusivityNamespace() *Job { + job.job.SetExclusivityNamespace() + return job +} + +func (job *Job) SetMaxRetries(value int) *Job { + job.job.SetMaxRetries(value) + return job +} + +func (job *Job) SetMaxOccurences(value int) *Job { + job.job.SetMaxOccurences(value) + return job +} + +func (job *Job) SetCategory(value string) *Job { + job.job.SetCategory(value) + return job +} + +func (job *Job) CreateJob() (*jw.Job, error) { + return job.model.CreateJob(job.job) +} + +/* +######################################################################################################## @(°_°)@ ####### +*/ diff --git a/factory/workflow.go b/factory/workflow.go new file mode 100644 index 0000000..7b63d94 --- /dev/null +++ b/factory/workflow.go @@ -0,0 +1,82 @@ +/* +------------------------------------------------------------------------------------------------------------------------ +####### sdk ####### Copyright (c) 2021 losyme ###################################################### MIT License ####### +------------------------------------------------------------------------------------------------------------------------ +*/ + +package factory + +import "forge.chapril.org/dune/jw" + +type Workflow struct { + wf *jw.Workflow + model Model +} + +func (wf *Workflow) SetID(value string) *Workflow { + wf.wf.SetID(value) + return wf +} + +func (wf *Workflow) SetType(value string) *Workflow { + wf.wf.SetType(value) + return wf +} + +func (wf *Workflow) SetDescription(value string) *Workflow { + wf.wf.SetDescription(value) + return wf +} + +func (wf *Workflow) SetOrigin(value string) *Workflow { + wf.wf.SetOrigin(value) + return wf +} + +func (wf *Workflow) SetPriority(value jw.Priority) *Workflow { + wf.wf.SetPriority(value) + return wf +} + +func (wf *Workflow) SetPriorityNone() *Workflow { + wf.wf.SetPriorityNone() + return wf +} + +func (wf *Workflow) SetPriorityLow() *Workflow { + wf.wf.SetPriorityLow() + return wf +} + +func (wf *Workflow) SetPriorityMedium() *Workflow { + wf.wf.SetPriorityMedium() + return wf +} + +func (wf *Workflow) SetPriorityHigh() *Workflow { + wf.wf.SetPriorityHigh() + return wf +} + +func (wf *Workflow) SetPriorityCritical() *Workflow { + wf.wf.SetPriorityCritical() + return wf +} + +func (wf *Workflow) SetData(key string, value interface{}) *Workflow { + wf.wf.SetData(key, value) + return wf +} + +func (wf *Workflow) SetExternalID(value string) *Workflow { + wf.wf.SetExternalID(value) + return wf +} + +func (wf *Workflow) CreateWorkflow() (*jw.Workflow, error) { + return wf.model.CreateWorkflow(wf.wf) +} + +/* +######################################################################################################## @(°_°)@ ####### +*/ diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..2b010e3 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module forge.chapril.org/dune/sdk + +go 1.17 + +require forge.chapril.org/dune/jw v0.0.0-20211114170701-4b66b0d705ea diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..b98a5e2 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +forge.chapril.org/dune/jw v0.0.0-20211114170701-4b66b0d705ea h1:EC1XXrDQ6E7Oed04iZFKsk2dbxJORBH2G+UxBFz42j4= +forge.chapril.org/dune/jw v0.0.0-20211114170701-4b66b0d705ea/go.mod h1:7CyK2ZvzHntSlOZ7kWcqVhkmUzlE0QI3uKW9kPbNbOY= diff --git a/sdk.go b/sdk.go new file mode 100644 index 0000000..b2206e2 --- /dev/null +++ b/sdk.go @@ -0,0 +1,21 @@ +/* +------------------------------------------------------------------------------------------------------------------------ +####### sdk ####### Copyright (c) 2021 losyme ###################################################### MIT License ####### +------------------------------------------------------------------------------------------------------------------------ +*/ + +package sdk + +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{}) +} + +/* +######################################################################################################## @(°_°)@ ####### +*/