mirror of
https://github.com/oarkflow/mq.git
synced 2025-10-20 14:45:36 +08:00
feat: Add connection
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/oarkflow/mq/examples/tasks"
|
"github.com/oarkflow/mq/examples/tasks"
|
||||||
"github.com/oarkflow/mq/services"
|
"github.com/oarkflow/mq/services"
|
||||||
|
|
||||||
@@ -54,6 +56,7 @@ func aSync() {
|
|||||||
if f.Notifier != nil {
|
if f.Notifier != nil {
|
||||||
f.Notifier.ToRoom("global", "message", result)
|
f.Notifier.ToRoom("global", "message", result)
|
||||||
}
|
}
|
||||||
|
log.Printf("DAG - FINAL_RESPONSE ~> TaskID: %s, Payload: %s, Topic: %s, Error: %v, Latency: %s", result.TaskID, result.Payload, result.Topic, result.Error, result.Latency)
|
||||||
})
|
})
|
||||||
setup(f)
|
setup(f)
|
||||||
err := f.Validate()
|
err := f.Validate()
|
||||||
|
@@ -71,7 +71,9 @@ func (e *EmailDelivery) ProcessTask(ctx context.Context, task *mq.Task) mq.Resul
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return mq.Result{Payload: task.Payload, Ctx: ctx}
|
data["email_sent"] = true
|
||||||
|
d, _ := json.Marshal(data)
|
||||||
|
return mq.Result{Payload: d, Ctx: ctx}
|
||||||
}
|
}
|
||||||
|
|
||||||
type SendSms struct {
|
type SendSms struct {
|
||||||
|
@@ -57,6 +57,12 @@
|
|||||||
<div class="w-screen mx-auto bg-white shadow-lg rounded-lg overflow-hidden">
|
<div class="w-screen mx-auto bg-white shadow-lg rounded-lg overflow-hidden">
|
||||||
<!-- Task Table Section -->
|
<!-- Task Table Section -->
|
||||||
<div class="p-4">
|
<div class="p-4">
|
||||||
|
<div class="flex gap-2 bg-slate-100 p-2">
|
||||||
|
<div class="flex-1 flex-grow">
|
||||||
|
<textarea id="payload" class="w-full py-1 px-2" placeholder="Enter your JSON task here"></textarea>
|
||||||
|
</div>
|
||||||
|
<div><button id="send-request" class="py-1 px-2 bg-blue-500 text-white" type="button">Send Task</button></div>
|
||||||
|
</div>
|
||||||
<h1 class="text-xl font-semibold text-gray-700 mb-4">Task Status</h1>
|
<h1 class="text-xl font-semibold text-gray-700 mb-4">Task Status</h1>
|
||||||
|
|
||||||
<!-- Scrollable Table -->
|
<!-- Scrollable Table -->
|
||||||
@@ -97,6 +103,43 @@
|
|||||||
<script>
|
<script>
|
||||||
(function(SS) {
|
(function(SS) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
document.getElementById('send-request').addEventListener('click', function() {
|
||||||
|
const input = document.getElementById('payload')
|
||||||
|
// Get the value from the textarea
|
||||||
|
const payloadData = JSON.parse(input.value);
|
||||||
|
|
||||||
|
// Prepare the data in the required JSON structure
|
||||||
|
const data = {
|
||||||
|
payload: payloadData
|
||||||
|
};
|
||||||
|
|
||||||
|
// Make the POST request
|
||||||
|
fetch('http://localhost:8083/request', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Network response was not ok');
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
console.log('Success:', data);
|
||||||
|
// Handle the response data if needed
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error('Error:', error);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
input.value = ""
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// New function to load the SVG dynamically
|
// New function to load the SVG dynamically
|
||||||
function loadSVG(url) {
|
function loadSVG(url) {
|
||||||
fetch(url)
|
fetch(url)
|
||||||
@@ -147,8 +190,6 @@
|
|||||||
popover.style.left = `${rect.left + window.scrollX + rect.width / 2}px`;
|
popover.style.left = `${rect.left + window.scrollX + rect.width / 2}px`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Function to find node data (status, result, error) by the node's ID
|
// Function to find node data (status, result, error) by the node's ID
|
||||||
function findNodeDataById(nodeId) {
|
function findNodeDataById(nodeId) {
|
||||||
for (const taskId in tasks) {
|
for (const taskId in tasks) {
|
||||||
|
1
go.mod
1
go.mod
@@ -9,7 +9,6 @@ require (
|
|||||||
github.com/oarkflow/errors v0.0.6
|
github.com/oarkflow/errors v0.0.6
|
||||||
github.com/oarkflow/expr v0.0.11
|
github.com/oarkflow/expr v0.0.11
|
||||||
github.com/oarkflow/json v0.0.13
|
github.com/oarkflow/json v0.0.13
|
||||||
github.com/oarkflow/sio v0.0.7
|
|
||||||
github.com/oarkflow/xid v1.2.5
|
github.com/oarkflow/xid v1.2.5
|
||||||
github.com/prometheus/client_golang v1.20.5
|
github.com/prometheus/client_golang v1.20.5
|
||||||
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c
|
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c
|
||||||
|
2
go.sum
2
go.sum
@@ -22,8 +22,6 @@ github.com/oarkflow/expr v0.0.11 h1:H6h+dIUlU+xDlijMXKQCh7TdE6MGVoFPpZU7q/dziRI=
|
|||||||
github.com/oarkflow/expr v0.0.11/go.mod h1:WgMZqP44h7SBwKyuGZwC15vj46lHtI0/QpKdEZpRVE4=
|
github.com/oarkflow/expr v0.0.11/go.mod h1:WgMZqP44h7SBwKyuGZwC15vj46lHtI0/QpKdEZpRVE4=
|
||||||
github.com/oarkflow/json v0.0.13 h1:/ZKW924/v4U1ht34WY7rj/GC/qW9+10IiV5+MR2vO0A=
|
github.com/oarkflow/json v0.0.13 h1:/ZKW924/v4U1ht34WY7rj/GC/qW9+10IiV5+MR2vO0A=
|
||||||
github.com/oarkflow/json v0.0.13/go.mod h1:S5BZA4/rM87+MY8mFrga3jISzxCL9RtLE6xHSk63VxI=
|
github.com/oarkflow/json v0.0.13/go.mod h1:S5BZA4/rM87+MY8mFrga3jISzxCL9RtLE6xHSk63VxI=
|
||||||
github.com/oarkflow/sio v0.0.7 h1:Bymu2GO9UccbgwWGcwqinhtFd9Pn+i24fkV6MFHyVx4=
|
|
||||||
github.com/oarkflow/sio v0.0.7/go.mod h1:tsmF+CUUdI0oksCGlLP+YT8aMF/dKXKAw1YXqQZtvtQ=
|
|
||||||
github.com/oarkflow/xid v1.2.5 h1:6RcNJm9+oZ/B647gkME9trCzhpxGQaSdNoD56Vmkeho=
|
github.com/oarkflow/xid v1.2.5 h1:6RcNJm9+oZ/B647gkME9trCzhpxGQaSdNoD56Vmkeho=
|
||||||
github.com/oarkflow/xid v1.2.5/go.mod h1:jG4YBh+swbjlWApGWDBYnsJEa7hi3CCpmuqhB3RAxVo=
|
github.com/oarkflow/xid v1.2.5/go.mod h1:jG4YBh+swbjlWApGWDBYnsJEa7hi3CCpmuqhB3RAxVo=
|
||||||
github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y=
|
github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y=
|
||||||
|
Reference in New Issue
Block a user