diff --git a/dag/v2/api.go b/dag/v2/api.go index b36990f..2edccf2 100644 --- a/dag/v2/api.go +++ b/dag/v2/api.go @@ -3,6 +3,7 @@ package v2 import ( "encoding/json" "fmt" + "log" "net/http" "strings" @@ -59,14 +60,18 @@ func (tm *DAG) taskStatusHandler(w http.ResponseWriter, r *http.Request) { key = strings.Split(key, Delimiter)[0] nodeID := strings.Split(value.NodeID, Delimiter)[0] rs := jsonparser.Delete(value.Result.Data, "html_content") + status := value.Status + if status == StatusProcessing { + status = StatusCompleted + } state := TaskState{ NodeID: nodeID, - Status: value.Status, + Status: status, UpdatedAt: value.UpdatedAt, Result: Result{ Data: rs, Error: value.Result.Error, - Status: value.Result.Status, + Status: status, }, } result[key] = state @@ -79,5 +84,6 @@ func (tm *DAG) taskStatusHandler(w http.ResponseWriter, r *http.Request) { func (tm *DAG) Start(addr string) { http.HandleFunc("/process", tm.render) http.HandleFunc("/task/status", tm.taskStatusHandler) + log.Printf("Server listening on http://%s", addr) http.ListenAndServe(addr, nil) } diff --git a/examples/v2.go b/examples/v2.go index 3285c90..4c98370 100644 --- a/examples/v2.go +++ b/examples/v2.go @@ -105,5 +105,5 @@ func main() { if dag.Error != nil { panic(dag.Error) } - dag.Start(":8080") + dag.Start("0.0.0.0:8080") } diff --git a/examples/webroot/form.html b/examples/webroot/form.html index bcff360..788d91f 100644 --- a/examples/webroot/form.html +++ b/examples/webroot/form.html @@ -4,24 +4,100 @@ User Data Form +

Enter Your Information

-
-
-

+
+ +
+ + +
-
-

+
+ + +
-
-

+
+ + +
- - +
+ +
+ +
+ + - \ No newline at end of file + diff --git a/examples/webroot/result.html b/examples/webroot/result.html index b4dcc52..b86c44a 100644 --- a/examples/webroot/result.html +++ b/examples/webroot/result.html @@ -15,16 +15,17 @@ h1 { text-align: center; color: #333; - padding-top: 20px; + padding-top: 30px; } .container { - width: 80%; + width: 90%; + max-width: 900px; margin: 0 auto; - padding: 20px; + padding: 30px; background-color: white; border-radius: 8px; - box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); + box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); } table { @@ -34,30 +35,49 @@ } table th, table td { - padding: 10px; + padding: 15px; border: 1px solid #ddd; text-align: left; + vertical-align: top; } table th { background-color: #f1f1f1; color: #333; + font-weight: bold; + } + + table tr:nth-child(even) { + background-color: #f9f9f9; + } + + table td pre { + background-color: #f5f5f5; + padding: 10px; + border-radius: 4px; + overflow: auto; + white-space: pre-wrap; + word-wrap: break-word; } .status-pending { color: orange; + font-weight: bold; } .status-processing { color: blue; + font-weight: bold; } .status-completed { color: green; + font-weight: bold; } .status-failed { color: red; + font-weight: bold; } .node-result { @@ -66,13 +86,53 @@ .node-result h2 { color: #333; + margin-bottom: 20px; } .footer { text-align: center; margin-top: 40px; padding-bottom: 20px; + font-size: 14px; + color: #555; } + + .footer a { + text-decoration: none; + color: #0066cc; + } + + .footer a:hover { + text-decoration: underline; + } + + .error-message { + color: red; + font-size: 18px; + margin-top: 20px; + } + + .success-message { + color: green; + font-size: 18px; + margin-top: 20px; + } + + .go-back { + display: inline-block; + margin-top: 10px; + padding: 10px 20px; + background-color: #0066cc; + color: white; + border-radius: 5px; + text-decoration: none; + font-weight: bold; + } + + .go-back:hover { + background-color: #005bb5; + } + @@ -101,12 +161,13 @@ .then(data => { if(data?.message) { document.getElementById('result').innerHTML = ` -

Error loading task result. ${data.message}


Go back`; +

Error loading task result: ${data.message}

+ Go back`; } else { const container = document.getElementById('result'); let htmlContent = ''; htmlContent += ` -

Final Task Result Go back

+

Final Task ResultGo Back

@@ -152,10 +213,10 @@ }) .catch(error => { console.log(error) - document.getElementById('result').innerHTML = '

Error loading task result.

'; + document.getElementById('result').innerHTML = '

Error loading task result.

'; }); } else { - document.getElementById('result').innerHTML = '

Task ID not provided.

'; + document.getElementById('result').innerHTML = '

Task ID not provided.

'; } function getStatusClass(status) { @@ -173,5 +234,6 @@ } } +
Task ID