-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatic.js
69 lines (53 loc) · 2.24 KB
/
static.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require('util').inspect.defaultOptions.depth = null
const grpc = require('@grpc/grpc-js')
const common = require('./codegen/temporal/api/common/v1/message_pb');
const taskqueue = require('./codegen/temporal/api/common/v1/message_pb');
const messages = require('./codegen/temporal/api/workflowservice/v1/request_response_pb');
const services = require('./codegen/temporal/api/workflowservice/v1/service_grpc_pb');
const client = new services.WorkflowServiceClient('localhost:7233', grpc.credentials.createInsecure());
const callback = (err, results) => {
if (err) {
console.log(err)
} else {
// This is the corresponding response object from './codegen/temporal/api/workflowservice/v1/request_response_pb'
console.log(results)
}
}
const listNamespaces = () => {
const req = new messages.ListNamespacesRequest()
client.listNamespaces(req, callback)
}
const startWorkflow = () => {
const payload = new common.Payload()
payload.setData(Buffer.from('"start-workflow-input"'))
payload.getMetadataMap().set('encoding', Buffer.from('json/plain'))
const input = new common.Payloads()
input.addPayloads(payload)
const workflowType = new common.WorkflowType()
workflowType.setName('MyWorkflow')
const taskQueue = new taskqueue.TaskQueue()
taskQueue.setName('MY_TASK_QUEUE')
const req = new messages.StartWorkflowExecutionRequest()
req.setNamespace('namespace')
req.setWorkflowId('my-workflow-id')
req.setRequestId('random-request-id')
req.setWorkflowType(workflowType)
req.setTaskQueue(taskQueue)
req.setInput(input)
client.StartWorkflowExecution(req, callback)
}
const signalWorkflow = () => {
const payload = new common.Payload()
payload.setData(Buffer.from('"signal-input"'))
payload.getMetadataMap().set('encoding', Buffer.from('json/plain'))
const input = new common.Payloads()
input.addPayloads(payload)
const execution = new common.WorkflowExecution()
execution.setWorkflowId('workflow-id')
const req = new messages.SignalWorkflowExecutionRequest()
req.setNamespace('namespace')
req.setSignalName('signalMethodName')
req.setWorkflowExecution(execution)
req.setInput(input)
client.signalWorkflowExecution(req, callback)
}