-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
87 lines (63 loc) · 2.34 KB
/
script.py
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import asyncio
import sys
import time
import signal
import sys
import json
# from intrepid import *
from intrepid import Intrepid, Qos, Node, DataType
# from intrepid.cache_manager import SqliteCacheManager
# from intrepid.config import DecisionApi, Bucketing
# from intrepid.hits import Screen
# from intrepid.tracking_manager import TrackingManagerConfig
# def signal_handler(sig, frame):
# print("Ctrl+C detected. Goodbye...")
# sys.exit(0)
# # Set up the signal handler for SIGINT (Ctrl+C)
# signal.signal(signal.SIGINT, signal_handler)
# Callback function to execute when inputs are ready
def my_callback_function(in1: int, in2:int) -> (float, bool):
# Add code here
time.sleep(0.02)
return 1. * (in1 + in2), True
def init():
print(sys.version)
# Create QoS policy for function node
qos = Qos(reliability="BestEffort", durability="TransientLocal")
qos.set_history("KeepLast")
qos.set_deadline(100) # Deadline expressed in milliseconds
# Create my node
mynode = Node("my_type")
mynode.add_input("flow", DataType.FLOW)
mynode.add_input("in1", DataType.INTEGER)
mynode.add_input("in2", DataType.INTEGER)
# mynode.add_input("in3", DataType.STRING)
# mynode.add_input("in4", DataType.FLOW)
# mynode.add_input("in5", DataType.ANY)
# mynode.add_input("in5", DataType.ANY_OR_FLOW)
# mynode.add_input("in5", DataType.WILDCARD)
mynode.add_output("flow", DataType.FLOW)
mynode.add_output("out1", DataType.FLOAT)
mynode.add_output("is_float", DataType.BOOLEAN)
mynode.get_inputs()
mynode_json = mynode.to_json()
print(mynode_json)
# Write to Graph
node_handler = Intrepid(node_id="python/project/node_type/node_id")
node_handler.register_node(mynode)
# Attach Qos policy to this node
node_handler.create_qos(qos)
# Request node status
node_status = node_handler.status()
# Request node info
node_info = node_handler.info()
# Register callback with node input. Callback and node inputs must have the same signature (same number/name/type)
node_handler.register_callback(my_callback_function)
# Start server and node execution
node_handler.start()
try:
while True:
init() # Your main program logic goes here
except KeyboardInterrupt:
print("KeyboardInterrupt detected. Goodbye...")
sys.exit(0)