Skip to content

Commit

Permalink
feat: WIP reworks a few things, adds subscriptions for results (#3487)
Browse files Browse the repository at this point in the history
* feat: WIP reworks a few things, adds subscriptions for results

* feat: wip

* feat: real time automation runs ✅

* feat: cleanup
  • Loading branch information
didimitrie authored Nov 11, 2024
1 parent aa76801 commit d77df66
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 20 deletions.
27 changes: 26 additions & 1 deletion packages/dui3/components/common/ProjectModelGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ import {
projectDetailsQuery,
versionCreatedSubscription,
userProjectsUpdatedSubscription,
projectUpdatedSubscription
projectUpdatedSubscription,
automateRunsSubscription
} from '~~/lib/graphql/mutationsAndQueries'
import { useMixpanel } from '~/lib/core/composables/mixpanel'
import type { ApolloError } from '@apollo/client/errors'
Expand Down Expand Up @@ -270,4 +271,28 @@ onResult((res) => {
displayReceiveComplete: false
})
})
const { onResult: onAutomateRunResult } = useSubscription(
automateRunsSubscription,
() => ({ projectId: props.project.projectId }),
() => ({ clientId })
)
onAutomateRunResult((res) => {
if (!res.data?.projectTriggeredAutomationsStatusUpdated) return
const relevantSender = props.project.senders.find(
(s) => s.modelId === res.data?.projectTriggeredAutomationsStatusUpdated.model.id
)
if (!relevantSender) return
hostAppStore.patchModel(
relevantSender.modelCardId,
{
automationRuns:
res.data?.projectTriggeredAutomationsStatusUpdated.run.functionRuns
},
false
)
})
</script>
41 changes: 25 additions & 16 deletions packages/dui3/components/model/CardBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@
</div>

<AutomateResultDialog
v-if="isSender && automationsRuns"
v-if="isSender && summary"
:model-card="modelCard"
:automation-runs="automationsRuns"
:automation-runs="
automateResult?.project.model.automationsStatus?.automationRuns
"
:project-id="modelCard.projectId"
:model-id="modelCard.modelId"
>
Expand Down Expand Up @@ -198,10 +200,7 @@ import { useAccountStore } from '~/store/accounts'
import type { IReceiverModelCard } from '~/lib/models/card/receiver'
import { useMixpanel } from '~/lib/core/composables/mixpanel'
import { useIntervalFn, useTimeoutFn } from '@vueuse/core'
import type {
AutomationRunItemFragment,
ProjectCommentsUpdatedMessage
} from '~/lib/common/generated/gql/graphql'
import type { ProjectCommentsUpdatedMessage } from '~/lib/common/generated/gql/graphql'
import { useFunctionRunsStatusSummary } from '~/lib/automate/runStatus'
const app = useNuxtApp()
Expand Down Expand Up @@ -261,7 +260,7 @@ const folderPath = computed(() => {
return withoutLast.join('/')
})
const { result: automateResult } = useQuery(
const { result: automateResult, onResult } = useQuery(
automateStatusQuery,
() => ({
projectId: props.project.projectId,
Expand All @@ -270,16 +269,26 @@ const { result: automateResult } = useQuery(
() => ({ clientId })
)
const automationsRuns = ref<AutomationRunItemFragment[] | undefined>(undefined)
const summary = computed(() =>
useFunctionRunsStatusSummary({
runs: automationsRuns.value as AutomationRunItemFragment[]
})
)
// on model card first load, populate any pre-existing automation runs here
onResult((res) => {
const automationRuns = res.data.project.model.automationsStatus?.automationRuns
if (!automationRuns) return
void store.patchModel(
props.modelCard.modelCardId,
{
automationRuns
},
false
)
})
// at first we can't get result directly?
watch(automateResult, (newValue) => {
automationsRuns.value = newValue?.project.model.automationsStatus?.automationRuns
const summary = computed(() => {
if (!props.modelCard.automationRuns) {
return undefined
}
return useFunctionRunsStatusSummary({
runs: props.modelCard.automationRuns
})
})
provide<IModelCard>('cardBase', props.modelCard)
Expand Down
5 changes: 5 additions & 0 deletions packages/dui3/lib/common/generated/gql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const documents = {
"\n query ModelDetails($modelId: String!, $projectId: String!) {\n project(id: $projectId) {\n id\n name\n model(id: $modelId) {\n id\n displayName\n name\n versions {\n totalCount\n items {\n id\n }\n }\n author {\n id\n name\n avatar\n }\n }\n }\n }\n": types.ModelDetailsDocument,
"\n query VersionDetails($projectId: String!, $versionId: String!, $modelId: String!) {\n project(id: $projectId) {\n id\n name\n model(id: $modelId) {\n id\n name\n versions(limit: 1) {\n items {\n id\n createdAt\n sourceApplication\n authorUser {\n id\n }\n }\n }\n version(id: $versionId) {\n id\n referencedObject\n message\n sourceApplication\n createdAt\n previewUrl\n }\n }\n }\n }\n": types.VersionDetailsDocument,
"\n subscription OnProjectVersionsUpdate($projectId: String!) {\n projectVersionsUpdated(id: $projectId) {\n id\n type\n version {\n id\n createdAt\n message\n sourceApplication\n authorUser {\n id\n name\n avatar\n }\n model {\n id\n name\n displayName\n }\n }\n }\n }\n": types.OnProjectVersionsUpdateDocument,
"\n subscription ProjectTriggeredAutomationsStatusUpdated($projectId: String!) {\n projectTriggeredAutomationsStatusUpdated(projectId: $projectId) {\n type\n version {\n id\n }\n model {\n id\n }\n project {\n id\n }\n run {\n ...AutomationRunItem\n }\n }\n }\n": types.ProjectTriggeredAutomationsStatusUpdatedDocument,
"\n subscription OnUserProjectsUpdated {\n userProjectsUpdated {\n id\n project {\n id\n visibility\n team {\n id\n role\n }\n }\n }\n }\n": types.OnUserProjectsUpdatedDocument,
"\n subscription ProjectUpdated($projectId: String!) {\n projectUpdated(id: $projectId) {\n id\n project {\n visibility\n }\n }\n }\n": types.ProjectUpdatedDocument,
"\n subscription Subscription($target: ViewerUpdateTrackingTarget!) {\n viewerUserActivityBroadcasted(target: $target) {\n userName\n userId\n sessionId\n user {\n name\n id\n avatar\n }\n status\n }\n }\n": types.SubscriptionDocument,
Expand Down Expand Up @@ -163,6 +164,10 @@ export function graphql(source: "\n query VersionDetails($projectId: String!, $
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n subscription OnProjectVersionsUpdate($projectId: String!) {\n projectVersionsUpdated(id: $projectId) {\n id\n type\n version {\n id\n createdAt\n message\n sourceApplication\n authorUser {\n id\n name\n avatar\n }\n model {\n id\n name\n displayName\n }\n }\n }\n }\n"): (typeof documents)["\n subscription OnProjectVersionsUpdate($projectId: String!) {\n projectVersionsUpdated(id: $projectId) {\n id\n type\n version {\n id\n createdAt\n message\n sourceApplication\n authorUser {\n id\n name\n avatar\n }\n model {\n id\n name\n displayName\n }\n }\n }\n }\n"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n subscription ProjectTriggeredAutomationsStatusUpdated($projectId: String!) {\n projectTriggeredAutomationsStatusUpdated(projectId: $projectId) {\n type\n version {\n id\n }\n model {\n id\n }\n project {\n id\n }\n run {\n ...AutomationRunItem\n }\n }\n }\n"): (typeof documents)["\n subscription ProjectTriggeredAutomationsStatusUpdated($projectId: String!) {\n projectTriggeredAutomationsStatusUpdated(projectId: $projectId) {\n type\n version {\n id\n }\n model {\n id\n }\n project {\n id\n }\n run {\n ...AutomationRunItem\n }\n }\n }\n"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down
Loading

0 comments on commit d77df66

Please sign in to comment.