This repository has been archived by the owner on Jul 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from uc-cdis/feat/workflow-db
Feat/workflow db
- Loading branch information
Showing
18 changed files
with
1,010 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package database | ||
|
||
const ( | ||
PostgresDB = "psql" | ||
usrTable = "usr" | ||
taskTable = "task" | ||
workflowTable = "workflow" | ||
|
||
dbcredentialpath = "/var/www/mariner/dbcreds.json" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package database | ||
|
||
type Dao interface { | ||
GetAllUsers() ([]User, error) | ||
CreateUser(name string, email string) (int64, error) | ||
UpdateUser(user *User) error | ||
DeleteUser(id int64) error | ||
GetUserById(id int64) (*User, error) | ||
|
||
GetAllWorkflows() ([]Workflow, error) | ||
CreateWorkflow(userId int64, lastTaskCompleted int64, definition string, hash string, stats string, inputs JsonBytesMap, output string, status string, metadata JsonBytesMap) (int64, error) | ||
UpdateWorkflow(workflow *Workflow) error | ||
DeleteWorkflow(id int64) error | ||
GetWorkflowById(id int64) (*Workflow, error) | ||
|
||
GetAllTasks() ([]Task, error) | ||
CreateTask(wf_id int64, name string, hash string, stats string, input JsonBytesMap, output string, status string, taskError string, wf_status string) (int64, error) | ||
UpdateTask(task *Task) error | ||
DeleteTask(id int64) error | ||
GetTaskById(id int64) (*Task, error) | ||
|
||
KillDao() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package database | ||
|
||
import log "github.com/sirupsen/logrus" | ||
|
||
func DaoFactory(daoType string) Dao { | ||
switch daoType { | ||
case "psql": | ||
return NewPSQLDao() | ||
|
||
default: | ||
log.Errorf("There is no current support for the daotype %s. Please select a different supported daotype", daoType) | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package database | ||
|
||
import ( | ||
"database/sql/driver" | ||
"encoding/json" | ||
"fmt" | ||
"time" | ||
) | ||
|
||
type User struct { | ||
ID int64 `db:"id"` | ||
Name string `db:"name"` | ||
Email string `db:"email"` | ||
CreatedAt time.Time `db:"created_at"` | ||
} | ||
|
||
type JsonBytesMap map[string]interface{} | ||
|
||
func (p JsonBytesMap) Value() (driver.Value, error) { | ||
j, err := json.Marshal(p) | ||
return j, err | ||
} | ||
|
||
func (p *JsonBytesMap) Scan(src interface{}) error { | ||
source, ok := src.([]byte) | ||
if !ok { | ||
return fmt.Errorf("type assertion .([]byte) failed") | ||
} | ||
|
||
var i interface{} | ||
err := json.Unmarshal(source, &i) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
*p, ok = i.(map[string]interface{}) | ||
if !ok { | ||
return fmt.Errorf("type assertion .(map[string]interface{}) failed") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
type Workflow struct { | ||
WorkFlowID int64 `db:"wf_id"` | ||
UserId int64 `db:"usr_id"` | ||
LastTaskCompleted int64 `db:"last_task_completed"` | ||
Definition string `db:"definition"` | ||
Hash string `db:"hash"` | ||
Stats string `db:"stats"` | ||
Inputs JsonBytesMap `db:"inputs"` | ||
Outputs string `db:"outputs"` | ||
Status string `db:"status"` | ||
StartedAt time.Time `db:"started_at"` | ||
EndedAt time.Time `db:"ended_at"` | ||
CreatedAt time.Time `db:"created_at"` | ||
UpdatedAt time.Time `db:"updated_at"` | ||
Metadata JsonBytesMap `db:"metadata"` | ||
} | ||
|
||
type Task struct { | ||
TaskId int64 `db:"task_id"` | ||
WorkFlowID int64 `db:"wf_id"` | ||
Name string `db:"name"` | ||
Hash string `db:"hash"` | ||
Stats string `db:"stats"` | ||
Input JsonBytesMap `db:"input"` | ||
Output string `db:"output"` | ||
Attempt int64 `db:"attempt"` | ||
Status string `db:"status"` | ||
ReturnCode int64 `db:"return_code"` | ||
Error string `db:"error"` | ||
WorkFlowStatus string `db:"wf_status"` | ||
CreatedAt time.Time `db:"created_at"` | ||
UpdatedAt time.Time `db:"updated_at"` | ||
} |
Oops, something went wrong.