Skip to content
Snippets Groups Projects
Verified Commit 8184ac91 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

fix: shell result was not written to db #39

parent 61ffb2ca
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,10 @@ func (id JobID) String() string {
return string(id)
}
type GetResult interface {
GetResult() string
}
// Priority is the priority of a job
type Priority int
......@@ -260,12 +264,22 @@ func (j *Job[T]) Execute(ctx context.Context) (RunGenericResult, error) {
newLog.ErrorMsg = runnerError.Error()
}
newLog.Result = CheckAndCallGetResult(r.Data)
j.logs = append(j.logs, newLog)
genericResult := RunGenericResult(r)
return genericResult, runnerError
}
func CheckAndCallGetResult[T any](data T) string {
switch v := any(data).(type) {
case GetResult:
return v.GetResult()
}
return ""
}
// Cancel cancels the job, currently a no-op
func (j *Job[T]) Cancel() error {
return nil
......
......@@ -27,6 +27,10 @@ type CounterResult struct {
Count int
}
func (c *CounterResult) GetResult() string {
return fmt.Sprintf("Count: %d", c.Count)
}
// CounterRunnable is a runnable that counts
type CounterRunnable struct {
Count int `json:"count" yaml:"count"`
......
......@@ -37,6 +37,10 @@ type FileOperationResult struct {
Content string // Optional, je nach Operation
}
func (f *FileOperationResult) GetResult() string {
return f.Content
}
const (
FileOperationRead = "read"
FileOperationWrite = "write"
......@@ -130,16 +134,16 @@ func (f *FileOperationRunnable) GetType() string {
return "fileoperation"
}
func (c *FileOperationRunnable) GetPersistence() RunnableImport {
func (f *FileOperationRunnable) GetPersistence() RunnableImport {
data := JSONMap{
"operation": c.Operation,
"filepath": c.FilePath,
"content": c.Content,
"operation": f.Operation,
"filepath": f.FilePath,
"content": f.Content,
}
return RunnableImport{
Type: c.GetType(),
Type: f.GetType(),
Data: data,
}
}
......@@ -38,6 +38,10 @@ type DBResult struct {
RowsAffected int
}
func (d *DBResult) GetResult() string {
return fmt.Sprintf("RowsAffected: %d", d.RowsAffected)
}
type DBRunnable struct {
Type string
DSN string
......@@ -93,16 +97,16 @@ func (d *DBRunnable) GetType() string {
return "db"
}
func (c *DBRunnable) GetPersistence() RunnableImport {
func (d *DBRunnable) GetPersistence() RunnableImport {
data := JSONMap{
"type": c.Type,
"dsn": c.DSN,
"query": c.Query,
"type": d.Type,
"dsn": d.DSN,
"query": d.Query,
}
return RunnableImport{
Type: c.GetType(),
Type: d.GetType(),
Data: data,
}
}
......@@ -46,6 +46,10 @@ type HTTPResult struct {
Body string
}
func (h *HTTPResult) GetResult() string {
return fmt.Sprintf("StatusCode: %d\n\n%s", h.StatusCode, h.Body)
}
type HTTPRunnable struct {
URL string
Method string
......@@ -90,17 +94,17 @@ func (h *HTTPRunnable) GetType() string {
return "http"
}
func (c *HTTPRunnable) GetPersistence() RunnableImport {
func (h *HTTPRunnable) GetPersistence() RunnableImport {
data := JSONMap{
"url": c.URL,
"method": c.Method,
"header": c.Header,
"body": c.Body,
"url": h.URL,
"method": h.Method,
"header": h.Header,
"body": h.Body,
}
return RunnableImport{
Type: c.GetType(),
Type: h.GetType(),
Data: data,
}
}
......@@ -75,6 +75,10 @@ type MailResult struct {
SmtpStatusCode uint
}
func (m *MailResult) GetResult() string {
return fmt.Sprintf("Sent: %t\n\nServerReply: %s\n\nSmtpStatusCode: %d", m.Sent, m.ServerReply, m.SmtpStatusCode)
}
type MailRunnable struct {
To string
From string
......@@ -146,22 +150,22 @@ func (m *MailRunnable) GetType() string {
return "mail"
}
func (c *MailRunnable) GetPersistence() RunnableImport {
func (m *MailRunnable) GetPersistence() RunnableImport {
data := JSONMap{
"to": c.To,
"from": c.From,
"subject": c.Subject,
"body": c.Body,
"server": c.Server,
"port": c.Port,
"username": c.Username,
"password": c.Password,
"headers": c.Headers,
"to": m.To,
"from": m.From,
"subject": m.Subject,
"body": m.Body,
"server": m.Server,
"port": m.Port,
"username": m.Username,
"password": m.Password,
"headers": m.Headers,
}
return RunnableImport{
Type: c.GetType(),
Type: m.GetType(),
Data: data,
}
}
......@@ -82,6 +82,10 @@ type SFTPResult struct {
FilesCopied []string
}
func (s *SFTPResult) GetResult() string {
return fmt.Sprintf("FilesCopied: %v", s.FilesCopied)
}
const (
CredentialTypePassword = "password"
CredentialTypeKey = "key"
......@@ -282,23 +286,23 @@ func (s *SFTPRunnable) GetType() string {
return "sftp"
}
func (c *SFTPRunnable) GetPersistence() RunnableImport {
func (s *SFTPRunnable) GetPersistence() RunnableImport {
data := JSONMap{
"host": c.Host,
"port": c.Port,
"user": c.User,
"insecure": c.Insecure,
"credential": c.Credential,
"credential_type": c.CredentialType,
"hostkey": c.HostKey,
"src_dir": c.SrcDir,
"dst_dir": c.DstDir,
"transfer_direction": c.TransferDirection,
"host": s.Host,
"port": s.Port,
"user": s.User,
"insecure": s.Insecure,
"credential": s.Credential,
"credential_type": s.CredentialType,
"hostkey": s.HostKey,
"src_dir": s.SrcDir,
"dst_dir": s.DstDir,
"transfer_direction": s.TransferDirection,
}
return RunnableImport{
Type: c.GetType(),
Type: s.GetType(),
Data: data,
}
}
......@@ -37,6 +37,10 @@ type ShellResult struct {
ExitCode int
}
func (s *ShellResult) GetResult() string {
return s.Output
}
type ShellRunnable struct {
ScriptPath string
Script string
......@@ -117,15 +121,15 @@ func (s *ShellRunnable) GetType() string {
return "shell"
}
func (c *ShellRunnable) GetPersistence() RunnableImport {
func (s *ShellRunnable) GetPersistence() RunnableImport {
data := JSONMap{
"scriptPath": c.ScriptPath,
"script": c.Script,
"scriptPath": s.ScriptPath,
"script": s.Script,
}
return RunnableImport{
Type: c.GetType(),
Type: s.GetType(),
Data: data,
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment