feat(ingestion): handle ingestion failure and cancellation in hostAppStore
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
HOST=127.0.0.1
|
||||
PORT=8082
|
||||
|
||||
NUXT_PUBLIC_MIXPANEL_TOKEN_ID=acd87c5a50b56df91a795e999812a3a4
|
||||
NUXT_PUBLIC_MIXPANEL_API_HOST=https://analytics.speckle.systems
|
||||
|
||||
SPECKLE_ACCOUNT_ID=undefined
|
||||
SPECKLE_TOKEN=undefined
|
||||
SPECKLE_USER_ID=undefined
|
||||
SPECKLE_URL=undefined
|
||||
SPECKLE_SAMPLE_PROJECT_ID=undefined
|
||||
SPECKLE_SAMPLE_MODEL_ID=undefined
|
||||
+29
-17
@@ -5,8 +5,7 @@ import { send, type Base } from '@speckle/objectsender'
|
||||
import { provideApolloClient, useMutation } from '@vue/apollo-composable'
|
||||
import {
|
||||
versionDetailsQuery,
|
||||
markReceivedVersionMutation,
|
||||
createVersionMutation
|
||||
markReceivedVersionMutation
|
||||
} from '~/lib/graphql/mutationsAndQueries'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import type { DUIAccount } from '~/store/accounts'
|
||||
@@ -16,6 +15,8 @@ import type { Emitter } from 'nanoevents'
|
||||
import { useDesktopService } from '~/lib/core/composables/desktopService'
|
||||
import type { ToastNotification } from '@speckle/ui-components'
|
||||
import { ToastNotificationType } from '@speckle/ui-components'
|
||||
import { useModelIngestion } from '../ingestion/composables/useModelIngestion'
|
||||
import type { ISenderModelCard } from '../models/card/send'
|
||||
|
||||
export type SendBatchViaBrowserArgs = {
|
||||
modelCardId: string
|
||||
@@ -466,24 +467,35 @@ export class ArchicadBridge {
|
||||
}
|
||||
|
||||
private async createVersion(args: CreateVersionArgs) {
|
||||
const accountStore = useAccountStore()
|
||||
const { accounts } = storeToRefs(accountStore)
|
||||
const account = accounts.value.find((acc) => acc.accountInfo.id === args.accountId)
|
||||
const hostAppStore = useHostAppStore()
|
||||
const { completeIngestionWithVersion } = useModelIngestion()
|
||||
|
||||
const createVersion = provideApolloClient((account as DUIAccount).client)(() =>
|
||||
useMutation(createVersionMutation)
|
||||
const modelCard = hostAppStore.models.find(
|
||||
(model) => model.modelCardId === args.modelCardId
|
||||
)
|
||||
|
||||
const hostAppStore = useHostAppStore()
|
||||
const ingestionId = hostAppStore.ingestionStatus[args.modelCardId]
|
||||
if (!ingestionId) {
|
||||
throw new Error(`Ingestion failed: Ingestion ID not found to create version.`)
|
||||
}
|
||||
|
||||
const result = await createVersion.mutate({
|
||||
input: {
|
||||
modelId: args.modelId,
|
||||
objectId: args.referencedObjectId,
|
||||
sourceApplication: hostAppStore.hostAppName,
|
||||
projectId: args.projectId
|
||||
}
|
||||
})
|
||||
return result?.data?.versionMutations?.create?.id
|
||||
const res = await completeIngestionWithVersion(
|
||||
modelCard as ISenderModelCard,
|
||||
ingestionId,
|
||||
args.referencedObjectId
|
||||
)
|
||||
|
||||
if (res?.statusData.__typename === 'ModelIngestionSuccessStatus') {
|
||||
return res?.statusData.versionId
|
||||
}
|
||||
|
||||
if (res?.statusData.__typename === 'ModelIngestionFailedStatus') {
|
||||
throw new Error(
|
||||
`Ingestion failed: ${res?.statusData.errorReason || 'Unknown error'}.`
|
||||
)
|
||||
}
|
||||
throw new Error(
|
||||
`Ingestion status does not match with the expected types as success or failure.`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,8 @@ type Documents = {
|
||||
"\n mutation CreateModelIngestion($input: ModelIngestionCreateInput!) {\n projectMutations {\n modelIngestionMutations {\n create(input: $input) {\n id\n }\n }\n }\n }\n": typeof types.CreateModelIngestionDocument,
|
||||
"\n mutation UpdateModelIngestionProgress($input: ModelIngestionUpdateInput!) {\n projectMutations {\n modelIngestionMutations {\n updateProgress(input: $input) {\n id\n }\n }\n }\n }\n": typeof types.UpdateModelIngestionProgressDocument,
|
||||
"\n mutation CompleteModelIngestionWithVersion($input: ModelIngestionSuccessInput!) {\n projectMutations {\n modelIngestionMutations {\n completeWithVersion(input: $input) {\n id\n statusData {\n __typename\n ... on ModelIngestionProcessingStatus {\n status\n progressMessage\n progress\n }\n ... on ModelIngestionSuccessStatus {\n status\n versionId\n }\n ... on ModelIngestionFailedStatus {\n errorStacktrace\n errorReason\n status\n }\n ... on ModelIngestionCancelledStatus {\n cancellationMessage\n status\n }\n ... on ModelIngestionQueuedStatus {\n progressMessage\n status\n }\n }\n }\n }\n }\n }\n": typeof types.CompleteModelIngestionWithVersionDocument,
|
||||
"\n mutation FailModelIngestionWithError($input: ModelIngestionFailedInput!) {\n projectMutations {\n modelIngestionMutations {\n failWithError(input: $input) {\n id\n statusData {\n __typename\n ... on ModelIngestionFailedStatus {\n status\n errorReason\n errorStacktrace\n }\n }\n }\n }\n }\n }\n": typeof types.FailModelIngestionWithErrorDocument,
|
||||
"\n mutation FailModelIngestionWithCancel($input: ModelIngestionCancelledInput!) {\n projectMutations {\n modelIngestionMutations {\n failWithCancel(input: $input) {\n id\n statusData {\n __typename\n ... on ModelIngestionCancelledStatus {\n status\n cancellationMessage\n }\n }\n }\n }\n }\n }\n": typeof types.FailModelIngestionWithCancelDocument,
|
||||
"\n fragment IssuesItem on Issue {\n id\n status\n title\n priority\n viewerState\n identifier\n resourceIdString\n activities(input: { limit: 1, sortDirection: asc }) {\n totalCount\n items {\n actor {\n id\n user {\n name\n id\n avatar\n }\n }\n eventType\n createdAt\n }\n }\n replies {\n totalCount\n items {\n id\n author {\n id\n user {\n name\n id\n avatar\n }\n }\n createdAt\n description {\n doc\n }\n }\n }\n description {\n doc\n }\n labels {\n hexColor\n id\n name\n }\n author {\n id\n user {\n id\n name\n avatar\n }\n }\n dueDate\n assignee {\n id\n user {\n id\n avatar\n name\n }\n }\n }\n": typeof types.IssuesItemFragmentDoc,
|
||||
"\n query IssuesList($projectId: String!) {\n project(id: $projectId) {\n id\n issues {\n totalCount\n items {\n ...IssuesItem\n }\n }\n }\n }\n": typeof types.IssuesListDocument,
|
||||
};
|
||||
@@ -106,6 +108,8 @@ const documents: Documents = {
|
||||
"\n mutation CreateModelIngestion($input: ModelIngestionCreateInput!) {\n projectMutations {\n modelIngestionMutations {\n create(input: $input) {\n id\n }\n }\n }\n }\n": types.CreateModelIngestionDocument,
|
||||
"\n mutation UpdateModelIngestionProgress($input: ModelIngestionUpdateInput!) {\n projectMutations {\n modelIngestionMutations {\n updateProgress(input: $input) {\n id\n }\n }\n }\n }\n": types.UpdateModelIngestionProgressDocument,
|
||||
"\n mutation CompleteModelIngestionWithVersion($input: ModelIngestionSuccessInput!) {\n projectMutations {\n modelIngestionMutations {\n completeWithVersion(input: $input) {\n id\n statusData {\n __typename\n ... on ModelIngestionProcessingStatus {\n status\n progressMessage\n progress\n }\n ... on ModelIngestionSuccessStatus {\n status\n versionId\n }\n ... on ModelIngestionFailedStatus {\n errorStacktrace\n errorReason\n status\n }\n ... on ModelIngestionCancelledStatus {\n cancellationMessage\n status\n }\n ... on ModelIngestionQueuedStatus {\n progressMessage\n status\n }\n }\n }\n }\n }\n }\n": types.CompleteModelIngestionWithVersionDocument,
|
||||
"\n mutation FailModelIngestionWithError($input: ModelIngestionFailedInput!) {\n projectMutations {\n modelIngestionMutations {\n failWithError(input: $input) {\n id\n statusData {\n __typename\n ... on ModelIngestionFailedStatus {\n status\n errorReason\n errorStacktrace\n }\n }\n }\n }\n }\n }\n": types.FailModelIngestionWithErrorDocument,
|
||||
"\n mutation FailModelIngestionWithCancel($input: ModelIngestionCancelledInput!) {\n projectMutations {\n modelIngestionMutations {\n failWithCancel(input: $input) {\n id\n statusData {\n __typename\n ... on ModelIngestionCancelledStatus {\n status\n cancellationMessage\n }\n }\n }\n }\n }\n }\n": types.FailModelIngestionWithCancelDocument,
|
||||
"\n fragment IssuesItem on Issue {\n id\n status\n title\n priority\n viewerState\n identifier\n resourceIdString\n activities(input: { limit: 1, sortDirection: asc }) {\n totalCount\n items {\n actor {\n id\n user {\n name\n id\n avatar\n }\n }\n eventType\n createdAt\n }\n }\n replies {\n totalCount\n items {\n id\n author {\n id\n user {\n name\n id\n avatar\n }\n }\n createdAt\n description {\n doc\n }\n }\n }\n description {\n doc\n }\n labels {\n hexColor\n id\n name\n }\n author {\n id\n user {\n id\n name\n avatar\n }\n }\n dueDate\n assignee {\n id\n user {\n id\n avatar\n name\n }\n }\n }\n": types.IssuesItemFragmentDoc,
|
||||
"\n query IssuesList($projectId: String!) {\n project(id: $projectId) {\n id\n issues {\n totalCount\n items {\n ...IssuesItem\n }\n }\n }\n }\n": types.IssuesListDocument,
|
||||
};
|
||||
@@ -300,6 +304,14 @@ export function graphql(source: "\n mutation UpdateModelIngestionProgress($inpu
|
||||
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
||||
*/
|
||||
export function graphql(source: "\n mutation CompleteModelIngestionWithVersion($input: ModelIngestionSuccessInput!) {\n projectMutations {\n modelIngestionMutations {\n completeWithVersion(input: $input) {\n id\n statusData {\n __typename\n ... on ModelIngestionProcessingStatus {\n status\n progressMessage\n progress\n }\n ... on ModelIngestionSuccessStatus {\n status\n versionId\n }\n ... on ModelIngestionFailedStatus {\n errorStacktrace\n errorReason\n status\n }\n ... on ModelIngestionCancelledStatus {\n cancellationMessage\n status\n }\n ... on ModelIngestionQueuedStatus {\n progressMessage\n status\n }\n }\n }\n }\n }\n }\n"): (typeof documents)["\n mutation CompleteModelIngestionWithVersion($input: ModelIngestionSuccessInput!) {\n projectMutations {\n modelIngestionMutations {\n completeWithVersion(input: $input) {\n id\n statusData {\n __typename\n ... on ModelIngestionProcessingStatus {\n status\n progressMessage\n progress\n }\n ... on ModelIngestionSuccessStatus {\n status\n versionId\n }\n ... on ModelIngestionFailedStatus {\n errorStacktrace\n errorReason\n status\n }\n ... on ModelIngestionCancelledStatus {\n cancellationMessage\n status\n }\n ... on ModelIngestionQueuedStatus {\n progressMessage\n status\n }\n }\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 mutation FailModelIngestionWithError($input: ModelIngestionFailedInput!) {\n projectMutations {\n modelIngestionMutations {\n failWithError(input: $input) {\n id\n statusData {\n __typename\n ... on ModelIngestionFailedStatus {\n status\n errorReason\n errorStacktrace\n }\n }\n }\n }\n }\n }\n"): (typeof documents)["\n mutation FailModelIngestionWithError($input: ModelIngestionFailedInput!) {\n projectMutations {\n modelIngestionMutations {\n failWithError(input: $input) {\n id\n statusData {\n __typename\n ... on ModelIngestionFailedStatus {\n status\n errorReason\n errorStacktrace\n }\n }\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 mutation FailModelIngestionWithCancel($input: ModelIngestionCancelledInput!) {\n projectMutations {\n modelIngestionMutations {\n failWithCancel(input: $input) {\n id\n statusData {\n __typename\n ... on ModelIngestionCancelledStatus {\n status\n cancellationMessage\n }\n }\n }\n }\n }\n }\n"): (typeof documents)["\n mutation FailModelIngestionWithCancel($input: ModelIngestionCancelledInput!) {\n projectMutations {\n modelIngestionMutations {\n failWithCancel(input: $input) {\n id\n statusData {\n __typename\n ... on ModelIngestionCancelledStatus {\n status\n cancellationMessage\n }\n }\n }\n }\n }\n }\n"];
|
||||
/**
|
||||
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
||||
*/
|
||||
|
||||
File diff suppressed because one or more lines are too long
+24
-3
@@ -44,8 +44,8 @@ export const useHostAppStore = defineStore('hostAppStore', () => {
|
||||
const { $openUrl } = useNuxtApp()
|
||||
const accountsStore = useAccountStore()
|
||||
const { checkUpdate } = useUpdateConnector()
|
||||
const { startIngestion, updateIngestion } = useModelIngestion()
|
||||
|
||||
const { startIngestion, updateIngestion, failIngestion, cancelIngestion } =
|
||||
useModelIngestion()
|
||||
const isDistributedBySpeckle = ref<boolean>(true)
|
||||
const latestAvailableVersion = ref<Version | null>(null)
|
||||
|
||||
@@ -399,6 +399,14 @@ export const useHostAppStore = defineStore('hostAppStore', () => {
|
||||
model.error = undefined
|
||||
void trackEvent('DUI3 Action', { name: 'Send Cancel' }, model.accountId)
|
||||
model.latestCreatedVersionId = undefined
|
||||
|
||||
// Cancel the ingestion if applicable
|
||||
if (shouldHandleIngestion.value) {
|
||||
const ingestionId = ingestionStatus.value[modelCardId]
|
||||
if (ingestionId) {
|
||||
await cancelIngestion(model, ingestionId, 'Cancelled by user')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
app.$sendBinding?.on('setModelsExpired', (modelCardIds) => {
|
||||
@@ -526,7 +534,7 @@ export const useHostAppStore = defineStore('hostAppStore', () => {
|
||||
}
|
||||
}
|
||||
|
||||
const setModelError = (args: {
|
||||
const setModelError = async (args: {
|
||||
modelCardId: string
|
||||
error: string | { errorMessage: string; dismissible?: boolean }
|
||||
}) => {
|
||||
@@ -542,6 +550,19 @@ export const useHostAppStore = defineStore('hostAppStore', () => {
|
||||
dismissible: boolean
|
||||
}
|
||||
}
|
||||
|
||||
// Fail the ingestion if applicable
|
||||
if (
|
||||
model.typeDiscriminator.includes('SenderModelCard') &&
|
||||
shouldHandleIngestion.value
|
||||
) {
|
||||
const ingestionId = ingestionStatus.value[args.modelCardId]
|
||||
if (ingestionId) {
|
||||
const errorMessage =
|
||||
typeof args.error === 'string' ? args.error : args.error.errorMessage
|
||||
await failIngestion(model as ISenderModelCard, ingestionId, errorMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: all bindings that need to send these model events should register.
|
||||
|
||||
Reference in New Issue
Block a user