Skip to content

Commit

Permalink
Merge pull request #568 from Gencaster/fix-node-jumping
Browse files Browse the repository at this point in the history
Fix node progression
  • Loading branch information
capital-G authored Sep 21, 2023
2 parents aec9347 + 4c558c0 commit 6e4aaee
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 19 deletions.
12 changes: 11 additions & 1 deletion caster-back/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,16 @@ type InvalidPythonCode {
errorCode: String!
}

"""Taken from ``logging`` module but omitting ``FATAL`` and ``WARN``."""
enum LogLevel {
CRITICAL
ERROR
WARNING
INFO
DEBUG
NOTSET
}

type LoginError {
errorMessage: String
}
Expand Down Expand Up @@ -710,7 +720,7 @@ type StreamLog {
streamPoint: StreamPoint!
stream: Stream!
origin: String
level: Int!
level: LogLevel!
message: String!
name: String
}
Expand Down
25 changes: 17 additions & 8 deletions caster-back/story_graph/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,13 +408,22 @@ async def get_next_node(self) -> Node:
).afirst()
# else return default out

if exit_door is None:
raise GraphDeadEnd()

try:
return (await exit_door.out_edges.order_by("?").select_related("in_node_door__node").afirst()).in_node_door.node # type: ignore
except AttributeError:
raise GraphDeadEnd()
while True:
if exit_door is None:
raise GraphDeadEnd()
try:
return (await exit_door.out_edges.order_by("?").select_related("in_node_door__node").afirst()).in_node_door.node # type: ignore
except AttributeError:
if exit_door.is_default:
raise GraphDeadEnd()
log.info(
f"Ran into a dead end on non-default door {exit_door.name} on node {self._current_node.name} - fallback to default door"
)
exit_door = await NodeDoor.objects.filter(
node=self._current_node,
door_type=NodeDoor.DoorType.OUTPUT,
is_default=True,
).afirst()

async def cleanup_sc_procedure(self) -> StreamInstruction:
log.debug("Run cleanup procedure on graph")
Expand Down Expand Up @@ -455,7 +464,7 @@ async def start(

# search for next node
try:
await self.get_next_node()
self._current_node = await self.get_next_node()
except GraphDeadEnd:
log.info(f"Ran into a dead end on {self.graph} on {self._current_node}")
return
Expand Down
4 changes: 3 additions & 1 deletion caster-back/stream/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

from . import frontend_types, models

LogLevelType = strawberry.enum(models.StreamLog.LogLevel) # type: ignore


@strawberry.django.filters.filter(models.StreamPoint, lookups=True)
class StreamPointFilter:
Expand Down Expand Up @@ -163,6 +165,6 @@ class StreamLog:
stream_point: StreamPoint
stream: Stream
origin: auto
level: auto
level: LogLevelType
message: auto
name: auto
50 changes: 45 additions & 5 deletions caster-editor/src/components/StreamLogs.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script lang="ts" setup>
import type { StreamLogsSubscription } from "@/graphql";
import { useStreamLogsSubscription, type StreamLog } from "@/graphql";
import { ElTable, ElTableColumn } from "element-plus";
import { useStreamLogsSubscription, type StreamLog, LogLevel } from "@/graphql";
import { Scope } from "@sentry/vue";
import { ElTable, ElTableColumn, ElTag } from "element-plus";
import { ref, toRef, type Ref } from "vue";
const props = defineProps<{
Expand All @@ -24,6 +25,35 @@ const { fetching } = useStreamLogsSubscription(
logs.value.push(newInfo.streamLogs);
},
);
const convertLogLevelType = (
level: string,
): "success" | "info" | "warning" | "danger" | "" => {
switch (level) {
case LogLevel.Critical: {
return "danger";
}
case LogLevel.Error: {
return "danger";
}
case LogLevel.Warning: {
return "warning";
}
case LogLevel.Info: {
return "success";
}
case LogLevel.Debug: {
return "info";
}
default: {
return "";
}
}
};
const formatDate = (date: string): string => {
return new Date(date).toLocaleString("sv-SE");
};
</script>

<template>
Expand All @@ -38,13 +68,23 @@ const { fetching } = useStreamLogsSubscription(
<ElTableColumn
prop="createdDate"
label="Time"
width="300"
/>
width="170"
>
<template #default="scope">
{{ formatDate(scope.row.createdDate) }}
</template>
</ElTableColumn>
<ElTableColumn
prop="level"
label="Level"
width="75"
/>
>
<template #default="scope">
<ElTag :type="convertLogLevelType(scope.row.level)">
{{ scope.row.level }}
</ElTag>
</template>
</ElTableColumn>
<ElTableColumn
prop="message"
label="Message"
Expand Down
14 changes: 12 additions & 2 deletions caster-editor/src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,16 @@ export type InvalidPythonCode = {
errorType: Scalars["String"];
};

/** Taken from ``logging`` module but omitting ``FATAL`` and ``WARN``. */
export enum LogLevel {
Critical = "CRITICAL",
Debug = "DEBUG",
Error = "ERROR",
Info = "INFO",
Notset = "NOTSET",
Warning = "WARNING",
}

export type LoginError = {
errorMessage?: Maybe<Scalars["String"]>;
};
Expand Down Expand Up @@ -790,7 +800,7 @@ export type StreamInstruction = {
/** StreamLog(uuid, created_date, modified_date, stream_point, stream, origin, level, message, name) */
export type StreamLog = {
createdDate: Scalars["DateTime"];
level: Scalars["Int"];
level: LogLevel;
message: Scalars["String"];
name?: Maybe<Scalars["String"]>;
origin?: Maybe<Scalars["String"]>;
Expand Down Expand Up @@ -1540,7 +1550,7 @@ export type StreamLogsSubscriptionVariables = Exact<{
export type StreamLogsSubscription = {
streamLogs: {
createdDate: any;
level: number;
level: LogLevel;
message: string;
name?: string | null;
uuid: any;
Expand Down
14 changes: 12 additions & 2 deletions caster-front/src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,16 @@ export type InvalidPythonCode = {
errorType: Scalars["String"];
};

/** Taken from ``logging`` module but omitting ``FATAL`` and ``WARN``. */
export enum LogLevel {
Critical = "CRITICAL",
Debug = "DEBUG",
Error = "ERROR",
Info = "INFO",
Notset = "NOTSET",
Warning = "WARNING",
}

export type LoginError = {
errorMessage?: Maybe<Scalars["String"]>;
};
Expand Down Expand Up @@ -790,7 +800,7 @@ export type StreamInstruction = {
/** StreamLog(uuid, created_date, modified_date, stream_point, stream, origin, level, message, name) */
export type StreamLog = {
createdDate: Scalars["DateTime"];
level: Scalars["Int"];
level: LogLevel;
message: Scalars["String"];
name?: Maybe<Scalars["String"]>;
origin?: Maybe<Scalars["String"]>;
Expand Down Expand Up @@ -1540,7 +1550,7 @@ export type StreamLogsSubscriptionVariables = Exact<{
export type StreamLogsSubscription = {
streamLogs: {
createdDate: any;
level: number;
level: LogLevel;
message: string;
name?: string | null;
uuid: any;
Expand Down

0 comments on commit 6e4aaee

Please sign in to comment.