Skip to content

Commit 925f17a

Browse files
committed
allow random activity by omitting activity
1 parent 39da86d commit 925f17a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

resources/plugins/simln/plugin.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import time
55
from enum import Enum
66
from pathlib import Path
7+
from typing import Optional
78

89
import click
910
from kubernetes.stream import stream
@@ -81,8 +82,9 @@ def _entrypoint(ctx, plugin_content: dict, warnet_content: dict):
8182
"""Called by entrypoint"""
8283
# write your plugin startup commands here
8384
activity = plugin_content.get(PluginContent.ACTIVITY.value)
84-
activity = json.loads(activity)
85-
print(activity)
85+
if activity:
86+
activity = json.loads(activity)
87+
print(activity)
8688
_launch_activity(activity, ctx.obj.get(PLUGIN_DIR_TAG))
8789

8890

@@ -132,8 +134,8 @@ def launch_activity(ctx, activity: str):
132134
print(_launch_activity(parsed_activity, plugin_dir))
133135

134136

135-
def _launch_activity(activity: list[dict], plugin_dir: str) -> str:
136-
"""Launch a SimLN chart which includes the `activity`"""
137+
def _launch_activity(activity: Optional[list[dict]], plugin_dir: str) -> str:
138+
"""Launch a SimLN chart which optionally includes the `activity`"""
137139
timestamp = int(time.time())
138140
name = f"simln-{timestamp}"
139141

@@ -156,7 +158,7 @@ def _launch_activity(activity: list[dict], plugin_dir: str) -> str:
156158
raise PluginError(f"Could not write sim.json to the init container: {name}")
157159

158160

159-
def _generate_activity_json(activity: list[dict]) -> str:
161+
def _generate_activity_json(activity: Optional[list[dict]]) -> str:
160162
nodes = []
161163

162164
for i in get_mission(LIGHTNING_MISSION):
@@ -169,7 +171,10 @@ def _generate_activity_json(activity: list[dict]) -> str:
169171
}
170172
nodes.append(node)
171173

172-
data = {"nodes": nodes, PluginContent.ACTIVITY.value: activity}
174+
if activity:
175+
data = {"nodes": nodes, PluginContent.ACTIVITY.value: activity}
176+
else:
177+
data = {"nodes": nodes}
173178

174179
return json.dumps(data, indent=2)
175180

0 commit comments

Comments
 (0)