wip stuff
This commit is contained in:
Родитель
d1d09e3c5b
Коммит
2331c5903a
|
@ -1,8 +1,10 @@
|
|||
enum AutomateRunStatus {
|
||||
PENDING
|
||||
INITIALIZING
|
||||
RUNNING
|
||||
SUCCEEDED
|
||||
FAILED
|
||||
ERROR
|
||||
}
|
||||
|
||||
enum AutomateRunTriggerType {
|
||||
|
@ -39,9 +41,7 @@ type VersionCreatedTrigger {
|
|||
union AutomationRunTrigger = VersionCreatedTrigger
|
||||
|
||||
type TriggeredAutomationsStatus {
|
||||
id: ID!
|
||||
status: AutomateRunStatus!
|
||||
statusMessage: String
|
||||
automationRuns: [AutomateRun!]!
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ type Automation {
|
|||
runs(cursor: String, limit: Int): AutomateRunCollection!
|
||||
currentRevision: AutomationRevision
|
||||
createdAt: DateTime!
|
||||
updatedAt: DateTime!
|
||||
# updatedAt: DateTime!
|
||||
}
|
||||
|
||||
type AutomateFunctionRun {
|
||||
|
@ -92,9 +92,9 @@ type AutomateFunctionRun {
|
|||
|
||||
type AutomateRun {
|
||||
id: ID!
|
||||
trigger: AutomationRunTrigger!
|
||||
# trigger: AutomationRunTrigger!
|
||||
status: AutomateRunStatus!
|
||||
reason: String
|
||||
statusMessage: String
|
||||
createdAt: DateTime!
|
||||
updatedAt: DateTime!
|
||||
automation: Automation!
|
||||
|
|
|
@ -1,9 +1,78 @@
|
|||
import {
|
||||
getAutomationByRunId,
|
||||
getLatestAutomationRunsForVersion,
|
||||
mergeRunStatus
|
||||
} from '@/modules/automate/services/automationRuns'
|
||||
import { AutomationRunStatus } from '@/modules/automate/types'
|
||||
import {
|
||||
Resolvers,
|
||||
AutomateRunTriggerType
|
||||
AutomateRunTriggerType,
|
||||
AutomateRunStatus,
|
||||
AutomateRun,
|
||||
Automation
|
||||
} from '@/modules/core/graph/generated/graphql'
|
||||
import { getBranchLatestCommits } from '@/modules/core/repositories/branches'
|
||||
|
||||
const statusMapping: Record<AutomationRunStatus, AutomateRunStatus> = {
|
||||
pending: AutomateRunStatus.Error,
|
||||
initializing: AutomateRunStatus.Initializing,
|
||||
running: AutomateRunStatus.Running,
|
||||
success: AutomateRunStatus.Succeeded,
|
||||
failure: AutomateRunStatus.Failed,
|
||||
error: AutomateRunStatus.Error
|
||||
}
|
||||
|
||||
const getVersionAutomationStatus = async (versionId: string) => {
|
||||
const latestRunsPerAutomation = await getLatestAutomationRunsForVersion(versionId)
|
||||
|
||||
const status =
|
||||
statusMapping[
|
||||
mergeRunStatus(
|
||||
latestRunsPerAutomation.flatMap((r) => r.functionRuns.map((r) => r.status))
|
||||
)
|
||||
]
|
||||
|
||||
// TODO: this resolver needs a graph type override
|
||||
// the run's automation has to be an async sub resolver
|
||||
const automationRuns: AutomateRun[] = latestRunsPerAutomation.map((r) => ({
|
||||
...r,
|
||||
status: statusMapping[r.status],
|
||||
functionRuns: r.functionRuns.map((fr) => ({
|
||||
...fr,
|
||||
status: statusMapping[fr.status]
|
||||
}))
|
||||
}))
|
||||
|
||||
return {
|
||||
status,
|
||||
automationRuns
|
||||
}
|
||||
}
|
||||
|
||||
export = {
|
||||
Model: {
|
||||
automationsStatus: async (parent) => {
|
||||
// no authz needed, if you can read the model, you can read its automation status
|
||||
const modelId = parent.id
|
||||
const [latestVersion] = await getBranchLatestCommits([modelId])
|
||||
|
||||
return await getVersionAutomationStatus(latestVersion.id)
|
||||
}
|
||||
},
|
||||
Version: {
|
||||
automationsStatus: async (parent) => {
|
||||
return await getVersionAutomationStatus(parent.id)
|
||||
}
|
||||
},
|
||||
AutomateRun: {
|
||||
automation: async (parent) => {
|
||||
const automation = await getAutomationByRunId(parent.id)
|
||||
if (!automation) throw new Error("The automation doesn't exist any more")
|
||||
|
||||
// TODO: graph type override
|
||||
return automation as unknown as Automation
|
||||
}
|
||||
},
|
||||
AutomationRevisionTriggerDefinition: {
|
||||
__resolveType(parent) {
|
||||
if (parent.type === AutomateRunTriggerType.VersionCreated) {
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
import {
|
||||
Automation,
|
||||
AutomationRun,
|
||||
AutomationRunStatus
|
||||
} from '@/modules/automate/types'
|
||||
|
||||
export const getLatestAutomationRunsForVersion = async (
|
||||
versionId: string
|
||||
): Promise<AutomationRun[]> => {
|
||||
console.log(versionId)
|
||||
return []
|
||||
}
|
||||
|
||||
const statusOrder: AutomationRunStatus[] = [
|
||||
'pending',
|
||||
'initializing',
|
||||
'running',
|
||||
'failure',
|
||||
'error'
|
||||
]
|
||||
|
||||
export const mergeRunStatus = (
|
||||
runStatuses: AutomationRunStatus[]
|
||||
): AutomationRunStatus => {
|
||||
if (!runStatuses.length) throw new Error('At-least one status is needed')
|
||||
|
||||
let currentStatus = 0
|
||||
for (const status of runStatuses) {
|
||||
const statusIndex = statusOrder.indexOf(status)
|
||||
if (statusIndex > currentStatus) currentStatus = statusIndex
|
||||
}
|
||||
return statusOrder[currentStatus]
|
||||
}
|
||||
|
||||
export const getAutomationByRunId = async (
|
||||
automationRunId: string
|
||||
): Promise<Automation | null> => {
|
||||
console.log(automationRunId)
|
||||
return null
|
||||
}
|
|
@ -55,6 +55,7 @@ export type AutomationRunTrigger = {
|
|||
|
||||
export type AutomationRunStatus =
|
||||
| 'pending'
|
||||
| 'initializing'
|
||||
| 'running'
|
||||
| 'success'
|
||||
| 'failure'
|
||||
|
|
|
@ -309,9 +309,8 @@ export type AutomateRun = {
|
|||
createdAt: Scalars['DateTime'];
|
||||
functionRuns: Array<AutomateFunctionRun>;
|
||||
id: Scalars['ID'];
|
||||
reason?: Maybe<Scalars['String']>;
|
||||
status: AutomateRunStatus;
|
||||
trigger: AutomationRunTrigger;
|
||||
statusMessage?: Maybe<Scalars['String']>;
|
||||
updatedAt: Scalars['DateTime'];
|
||||
};
|
||||
|
||||
|
@ -323,8 +322,10 @@ export type AutomateRunCollection = {
|
|||
};
|
||||
|
||||
export enum AutomateRunStatus {
|
||||
Error = 'ERROR',
|
||||
Failed = 'FAILED',
|
||||
Initializing = 'INITIALIZING',
|
||||
Pending = 'PENDING',
|
||||
Running = 'RUNNING',
|
||||
Succeeded = 'SUCCEEDED'
|
||||
}
|
||||
|
@ -341,7 +342,6 @@ export type Automation = {
|
|||
id: Scalars['ID'];
|
||||
name: Scalars['String'];
|
||||
runs: AutomateRunCollection;
|
||||
updatedAt: Scalars['DateTime'];
|
||||
};
|
||||
|
||||
|
||||
|
@ -2884,9 +2884,7 @@ export enum TokenResourceIdentifierType {
|
|||
export type TriggeredAutomationsStatus = {
|
||||
__typename?: 'TriggeredAutomationsStatus';
|
||||
automationRuns: Array<AutomateRun>;
|
||||
id: Scalars['ID'];
|
||||
status: AutomateRunStatus;
|
||||
statusMessage?: Maybe<Scalars['String']>;
|
||||
};
|
||||
|
||||
export type UpdateModelInput = {
|
||||
|
@ -3364,7 +3362,7 @@ export type ResolversTypes = {
|
|||
AutomateFunctionRun: ResolverTypeWrapper<Omit<AutomateFunctionRun, 'function'> & { function: ResolversTypes['AutomateFunction'] }>;
|
||||
AutomateFunctionRunStatusReportInput: AutomateFunctionRunStatusReportInput;
|
||||
AutomateFunctionsFilter: AutomateFunctionsFilter;
|
||||
AutomateRun: ResolverTypeWrapper<Omit<AutomateRun, 'automation' | 'functionRuns' | 'trigger'> & { automation: ResolversTypes['Automation'], functionRuns: Array<ResolversTypes['AutomateFunctionRun']>, trigger: ResolversTypes['AutomationRunTrigger'] }>;
|
||||
AutomateRun: ResolverTypeWrapper<Omit<AutomateRun, 'automation' | 'functionRuns'> & { automation: ResolversTypes['Automation'], functionRuns: Array<ResolversTypes['AutomateFunctionRun']> }>;
|
||||
AutomateRunCollection: ResolverTypeWrapper<Omit<AutomateRunCollection, 'items'> & { items: Array<ResolversTypes['AutomateRun']> }>;
|
||||
AutomateRunStatus: AutomateRunStatus;
|
||||
AutomateRunTriggerType: AutomateRunTriggerType;
|
||||
|
@ -3569,7 +3567,7 @@ export type ResolversParentTypes = {
|
|||
AutomateFunctionRun: Omit<AutomateFunctionRun, 'function'> & { function: ResolversParentTypes['AutomateFunction'] };
|
||||
AutomateFunctionRunStatusReportInput: AutomateFunctionRunStatusReportInput;
|
||||
AutomateFunctionsFilter: AutomateFunctionsFilter;
|
||||
AutomateRun: Omit<AutomateRun, 'automation' | 'functionRuns' | 'trigger'> & { automation: ResolversParentTypes['Automation'], functionRuns: Array<ResolversParentTypes['AutomateFunctionRun']>, trigger: ResolversParentTypes['AutomationRunTrigger'] };
|
||||
AutomateRun: Omit<AutomateRun, 'automation' | 'functionRuns'> & { automation: ResolversParentTypes['Automation'], functionRuns: Array<ResolversParentTypes['AutomateFunctionRun']> };
|
||||
AutomateRunCollection: Omit<AutomateRunCollection, 'items'> & { items: Array<ResolversParentTypes['AutomateRun']> };
|
||||
Automation: Omit<Automation, 'currentRevision' | 'runs'> & { currentRevision?: Maybe<ResolversParentTypes['AutomationRevision']>, runs: ResolversParentTypes['AutomateRunCollection'] };
|
||||
AutomationCollection: Omit<AutomationCollection, 'items'> & { items: Array<ResolversParentTypes['Automation']> };
|
||||
|
@ -3909,9 +3907,8 @@ export type AutomateRunResolvers<ContextType = GraphQLContext, ParentType extend
|
|||
createdAt?: Resolver<ResolversTypes['DateTime'], ParentType, ContextType>;
|
||||
functionRuns?: Resolver<Array<ResolversTypes['AutomateFunctionRun']>, ParentType, ContextType>;
|
||||
id?: Resolver<ResolversTypes['ID'], ParentType, ContextType>;
|
||||
reason?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
|
||||
status?: Resolver<ResolversTypes['AutomateRunStatus'], ParentType, ContextType>;
|
||||
trigger?: Resolver<ResolversTypes['AutomationRunTrigger'], ParentType, ContextType>;
|
||||
statusMessage?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
|
||||
updatedAt?: Resolver<ResolversTypes['DateTime'], ParentType, ContextType>;
|
||||
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
|
||||
};
|
||||
|
@ -3930,7 +3927,6 @@ export type AutomationResolvers<ContextType = GraphQLContext, ParentType extends
|
|||
id?: Resolver<ResolversTypes['ID'], ParentType, ContextType>;
|
||||
name?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
|
||||
runs?: Resolver<ResolversTypes['AutomateRunCollection'], ParentType, ContextType, Partial<AutomationRunsArgs>>;
|
||||
updatedAt?: Resolver<ResolversTypes['DateTime'], ParentType, ContextType>;
|
||||
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
|
||||
};
|
||||
|
||||
|
@ -4747,9 +4743,7 @@ export type TokenResourceIdentifierResolvers<ContextType = GraphQLContext, Paren
|
|||
|
||||
export type TriggeredAutomationsStatusResolvers<ContextType = GraphQLContext, ParentType extends ResolversParentTypes['TriggeredAutomationsStatus'] = ResolversParentTypes['TriggeredAutomationsStatus']> = {
|
||||
automationRuns?: Resolver<Array<ResolversTypes['AutomateRun']>, ParentType, ContextType>;
|
||||
id?: Resolver<ResolversTypes['ID'], ParentType, ContextType>;
|
||||
status?: Resolver<ResolversTypes['AutomateRunStatus'], ParentType, ContextType>;
|
||||
statusMessage?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
|
||||
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
|
||||
};
|
||||
|
||||
|
|
|
@ -299,9 +299,8 @@ export type AutomateRun = {
|
|||
createdAt: Scalars['DateTime'];
|
||||
functionRuns: Array<AutomateFunctionRun>;
|
||||
id: Scalars['ID'];
|
||||
reason?: Maybe<Scalars['String']>;
|
||||
status: AutomateRunStatus;
|
||||
trigger: AutomationRunTrigger;
|
||||
statusMessage?: Maybe<Scalars['String']>;
|
||||
updatedAt: Scalars['DateTime'];
|
||||
};
|
||||
|
||||
|
@ -313,8 +312,10 @@ export type AutomateRunCollection = {
|
|||
};
|
||||
|
||||
export enum AutomateRunStatus {
|
||||
Error = 'ERROR',
|
||||
Failed = 'FAILED',
|
||||
Initializing = 'INITIALIZING',
|
||||
Pending = 'PENDING',
|
||||
Running = 'RUNNING',
|
||||
Succeeded = 'SUCCEEDED'
|
||||
}
|
||||
|
@ -331,7 +332,6 @@ export type Automation = {
|
|||
id: Scalars['ID'];
|
||||
name: Scalars['String'];
|
||||
runs: AutomateRunCollection;
|
||||
updatedAt: Scalars['DateTime'];
|
||||
};
|
||||
|
||||
|
||||
|
@ -2874,9 +2874,7 @@ export enum TokenResourceIdentifierType {
|
|||
export type TriggeredAutomationsStatus = {
|
||||
__typename?: 'TriggeredAutomationsStatus';
|
||||
automationRuns: Array<AutomateRun>;
|
||||
id: Scalars['ID'];
|
||||
status: AutomateRunStatus;
|
||||
statusMessage?: Maybe<Scalars['String']>;
|
||||
};
|
||||
|
||||
export type UpdateModelInput = {
|
||||
|
|
|
@ -125,15 +125,14 @@ export async function buildMocksConfig(): Promise<{
|
|||
}
|
||||
},
|
||||
AutomateRun: {
|
||||
trigger: async () => {
|
||||
const { model, version } = await getRandomModelVersion()
|
||||
|
||||
return {
|
||||
type: AutomateRunTriggerType.VersionCreated,
|
||||
version,
|
||||
model
|
||||
}
|
||||
}
|
||||
// trigger: async () => {
|
||||
// const { model, version } = await getRandomModelVersion()
|
||||
// return {
|
||||
// type: AutomateRunTriggerType.VersionCreated,
|
||||
// version,
|
||||
// model
|
||||
// }
|
||||
// }
|
||||
},
|
||||
ProjectAutomationMutations: {
|
||||
update: (_parent, args) => {
|
||||
|
|
|
@ -300,9 +300,8 @@ export type AutomateRun = {
|
|||
createdAt: Scalars['DateTime'];
|
||||
functionRuns: Array<AutomateFunctionRun>;
|
||||
id: Scalars['ID'];
|
||||
reason?: Maybe<Scalars['String']>;
|
||||
status: AutomateRunStatus;
|
||||
trigger: AutomationRunTrigger;
|
||||
statusMessage?: Maybe<Scalars['String']>;
|
||||
updatedAt: Scalars['DateTime'];
|
||||
};
|
||||
|
||||
|
@ -314,8 +313,10 @@ export type AutomateRunCollection = {
|
|||
};
|
||||
|
||||
export enum AutomateRunStatus {
|
||||
Error = 'ERROR',
|
||||
Failed = 'FAILED',
|
||||
Initializing = 'INITIALIZING',
|
||||
Pending = 'PENDING',
|
||||
Running = 'RUNNING',
|
||||
Succeeded = 'SUCCEEDED'
|
||||
}
|
||||
|
@ -332,7 +333,6 @@ export type Automation = {
|
|||
id: Scalars['ID'];
|
||||
name: Scalars['String'];
|
||||
runs: AutomateRunCollection;
|
||||
updatedAt: Scalars['DateTime'];
|
||||
};
|
||||
|
||||
|
||||
|
@ -2875,9 +2875,7 @@ export enum TokenResourceIdentifierType {
|
|||
export type TriggeredAutomationsStatus = {
|
||||
__typename?: 'TriggeredAutomationsStatus';
|
||||
automationRuns: Array<AutomateRun>;
|
||||
id: Scalars['ID'];
|
||||
status: AutomateRunStatus;
|
||||
statusMessage?: Maybe<Scalars['String']>;
|
||||
};
|
||||
|
||||
export type UpdateModelInput = {
|
||||
|
|
Загрузка…
Ссылка в новой задаче