mirror of
https://github.com/harness/drone.git
synced 2025-05-10 21:00:04 +08:00
fix multiple event streams bug and only open logs stream if step open (#525)
This commit is contained in:
parent
ebe2800101
commit
cd6e800075
@ -40,7 +40,7 @@ const ConsoleStep: FC<ConsoleStepProps> = ({ step, stageNumber, repoPath, pipeli
|
|||||||
}, [stageNumber])
|
}, [stageNumber])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (step?.status === ExecutionState.RUNNING) {
|
if (step?.status === ExecutionState.RUNNING && isOpened) {
|
||||||
if (eventSourceRef.current) {
|
if (eventSourceRef.current) {
|
||||||
eventSourceRef.current.close()
|
eventSourceRef.current.close()
|
||||||
setStreamingLogs([])
|
setStreamingLogs([])
|
||||||
@ -64,6 +64,7 @@ const ConsoleStep: FC<ConsoleStepProps> = ({ step, stageNumber, repoPath, pipeli
|
|||||||
setStreamingLogs([])
|
setStreamingLogs([])
|
||||||
if (eventSourceRef.current) eventSourceRef.current.close()
|
if (eventSourceRef.current) eventSourceRef.current.close()
|
||||||
}
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [executionNumber, isOpened, pipelineName, repoPath, stageNumber, step?.name, step?.number, step?.status])
|
}, [executionNumber, isOpened, pipelineName, repoPath, stageNumber, step?.name, step?.number, step?.status])
|
||||||
|
|
||||||
let icon
|
let icon
|
||||||
|
@ -10,3 +10,11 @@
|
|||||||
.withError {
|
.withError {
|
||||||
display: grid;
|
display: grid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
top: 0 !important;
|
||||||
|
background-color: var(--red) !important;
|
||||||
|
height: var(--log-content-header-height) !important;
|
||||||
|
padding: var(--spacing-medium) !important;
|
||||||
|
font-weight: 600 !important;
|
||||||
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
// This is an auto-generated file
|
// This is an auto-generated file
|
||||||
|
export declare const error: string
|
||||||
export declare const main: string
|
export declare const main: string
|
||||||
export declare const pageBody: string
|
export declare const pageBody: string
|
||||||
export declare const withError: string
|
export declare const withError: string
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import { Container, PageBody } from '@harnessio/uicore'
|
import { Container, PageBody, Text } from '@harnessio/uicore'
|
||||||
import React, { useEffect, useState } from 'react'
|
import React, { useCallback, useEffect, useMemo, useState } from 'react'
|
||||||
import cx from 'classnames'
|
import cx from 'classnames'
|
||||||
import { useParams } from 'react-router-dom'
|
import { useParams } from 'react-router-dom'
|
||||||
import { useGet } from 'restful-react'
|
import { useGet } from 'restful-react'
|
||||||
|
import { Color, FontVariation } from '@harnessio/design-system'
|
||||||
import { routes, type CODEProps } from 'RouteDefinitions'
|
import { routes, type CODEProps } from 'RouteDefinitions'
|
||||||
import type { TypesExecution } from 'services/code'
|
import type { TypesExecution } from 'services/code'
|
||||||
import ExecutionStageList from 'components/ExecutionStageList/ExecutionStageList'
|
import ExecutionStageList from 'components/ExecutionStageList/ExecutionStageList'
|
||||||
@ -46,10 +47,8 @@ const Execution = () => {
|
|||||||
}
|
}
|
||||||
}, [execution])
|
}, [execution])
|
||||||
|
|
||||||
useSpaceSSE({
|
const onEvent = useCallback(
|
||||||
space,
|
data => {
|
||||||
events: ['execution_updated', 'execution_completed', 'execution_canceled', 'execution_running'],
|
|
||||||
onEvent: data => {
|
|
||||||
if (
|
if (
|
||||||
data?.repo_id === execution?.repo_id &&
|
data?.repo_id === execution?.repo_id &&
|
||||||
data?.pipeline_id === execution?.pipeline_id &&
|
data?.pipeline_id === execution?.pipeline_id &&
|
||||||
@ -59,7 +58,24 @@ const Execution = () => {
|
|||||||
executionRefetch()
|
executionRefetch()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
shouldRun: [ExecutionState.RUNNING, ExecutionState.PENDING].includes(getStatus(execution?.status))
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
[execution?.number, execution?.pipeline_id, execution?.repo_id]
|
||||||
|
)
|
||||||
|
|
||||||
|
const shouldRun = useMemo(() => {
|
||||||
|
return [ExecutionState.RUNNING, ExecutionState.PENDING].includes(getStatus(execution?.status))
|
||||||
|
}, [execution?.status])
|
||||||
|
|
||||||
|
const events = useMemo(
|
||||||
|
() => ['execution_updated', 'execution_completed', 'execution_canceled', 'execution_running'],
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
|
||||||
|
useSpaceSSE({
|
||||||
|
space,
|
||||||
|
events,
|
||||||
|
onEvent,
|
||||||
|
shouldRun
|
||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -102,7 +118,14 @@ const Execution = () => {
|
|||||||
// button: NewExecutionButton
|
// button: NewExecutionButton
|
||||||
}}>
|
}}>
|
||||||
<LoadingSpinner visible={loading || isInitialLoad} withBorder={!!execution && isInitialLoad} />
|
<LoadingSpinner visible={loading || isInitialLoad} withBorder={!!execution && isInitialLoad} />
|
||||||
{execution && (
|
{execution?.error && (
|
||||||
|
<Container className={css.error}>
|
||||||
|
<Text font={{ variation: FontVariation.BODY }} color={Color.WHITE}>
|
||||||
|
{execution?.error}
|
||||||
|
</Text>
|
||||||
|
</Container>
|
||||||
|
)}
|
||||||
|
{execution && !execution?.error && (
|
||||||
<Split split="vertical" size={300} minSize={200} maxSize={400}>
|
<Split split="vertical" size={300} minSize={200} maxSize={400}>
|
||||||
<ExecutionStageList
|
<ExecutionStageList
|
||||||
stages={execution?.stages || []}
|
stages={execution?.stages || []}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect, useMemo, useState } from 'react'
|
import React, { useCallback, useEffect, useMemo, useState } from 'react'
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
ButtonVariation,
|
ButtonVariation,
|
||||||
@ -22,7 +22,7 @@ import { useAppContext } from 'AppContext'
|
|||||||
import { NoResultCard } from 'components/NoResultCard/NoResultCard'
|
import { NoResultCard } from 'components/NoResultCard/NoResultCard'
|
||||||
import { LIST_FETCHING_LIMIT, PageBrowserProps, getErrorMessage, timeDistance, voidFn } from 'utils/Utils'
|
import { LIST_FETCHING_LIMIT, PageBrowserProps, getErrorMessage, timeDistance, voidFn } from 'utils/Utils'
|
||||||
import type { CODEProps } from 'RouteDefinitions'
|
import type { CODEProps } from 'RouteDefinitions'
|
||||||
import type { EnumTriggerAction, TypesExecution } from 'services/code'
|
import type { EnumTriggerAction, TypesExecution, TypesPipeline } from 'services/code'
|
||||||
import { useQueryParams } from 'hooks/useQueryParams'
|
import { useQueryParams } from 'hooks/useQueryParams'
|
||||||
import { usePageIndex } from 'hooks/usePageIndex'
|
import { usePageIndex } from 'hooks/usePageIndex'
|
||||||
import { ResourceListingPagination } from 'components/ResourceListingPagination/ResourceListingPagination'
|
import { ResourceListingPagination } from 'components/ResourceListingPagination/ResourceListingPagination'
|
||||||
@ -49,6 +49,11 @@ const ExecutionList = () => {
|
|||||||
|
|
||||||
const { repoMetadata, error, loading, refetch, space } = useGetRepositoryMetadata()
|
const { repoMetadata, error, loading, refetch, space } = useGetRepositoryMetadata()
|
||||||
|
|
||||||
|
const { data: pipelineData, error: pipelineError } = useGet<TypesPipeline>({
|
||||||
|
path: `/api/v1/repos/${repoMetadata?.path}/+/pipelines/${pipeline}`,
|
||||||
|
lazy: !repoMetadata
|
||||||
|
})
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: executions,
|
data: executions,
|
||||||
error: executionsError,
|
error: executionsError,
|
||||||
@ -69,20 +74,27 @@ const ExecutionList = () => {
|
|||||||
}
|
}
|
||||||
}, [executions])
|
}, [executions])
|
||||||
|
|
||||||
useSpaceSSE({
|
const onEvent = useCallback(
|
||||||
space,
|
data => {
|
||||||
events: ['execution_updated', 'execution_completed', 'execution_canceled', 'execution_running'],
|
|
||||||
onEvent: data => {
|
|
||||||
// ideally this would include number - so we only check for executions on the page - but what if new executions are kicked off? - could check for ids that are higher than the lowest id on the page?
|
// ideally this would include number - so we only check for executions on the page - but what if new executions are kicked off? - could check for ids that are higher than the lowest id on the page?
|
||||||
if (
|
if (repoMetadata?.id === data?.repo_id && pipelineData?.id === data?.pipeline_id) {
|
||||||
executions?.some(
|
|
||||||
execution => execution.repo_id === data?.repo_id && execution.pipeline_id === data?.pipeline_id
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
//TODO - revisit full refresh - can I use the message to update the execution?
|
//TODO - revisit full refresh - can I use the message to update the execution?
|
||||||
executionsRefetch()
|
executionsRefetch()
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
[pipelineData?.id, repoMetadata?.id]
|
||||||
|
)
|
||||||
|
|
||||||
|
const events = useMemo(
|
||||||
|
() => ['execution_updated', 'execution_completed', 'execution_canceled', 'execution_running'],
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
|
||||||
|
useSpaceSSE({
|
||||||
|
space,
|
||||||
|
events,
|
||||||
|
onEvent
|
||||||
})
|
})
|
||||||
|
|
||||||
const { openModal: openRunPipelineModal } = useRunPipelineModal()
|
const { openModal: openRunPipelineModal } = useRunPipelineModal()
|
||||||
@ -183,8 +195,8 @@ const ExecutionList = () => {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<PageBody
|
<PageBody
|
||||||
className={cx({ [css.withError]: !!error })}
|
className={cx({ [css.withError]: !!error || !!pipelineError || !!executionsError })}
|
||||||
error={error ? getErrorMessage(error || executionsError) : null}
|
error={error || pipeline || executionsError ? getErrorMessage(error || pipelineError || executionsError) : null}
|
||||||
retryOnError={voidFn(refetch)}
|
retryOnError={voidFn(refetch)}
|
||||||
noData={{
|
noData={{
|
||||||
when: () => executions?.length === 0,
|
when: () => executions?.length === 0,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect, useMemo, useState } from 'react'
|
import React, { useCallback, useEffect, useMemo, useState } from 'react'
|
||||||
import { Classes, Intent, Menu, MenuItem, Popover, Position } from '@blueprintjs/core'
|
import { Classes, Intent, Menu, MenuItem, Popover, Position } from '@blueprintjs/core'
|
||||||
import {
|
import {
|
||||||
Avatar,
|
Avatar,
|
||||||
@ -78,16 +78,27 @@ const PipelineList = () => {
|
|||||||
}
|
}
|
||||||
}, [pipelines])
|
}, [pipelines])
|
||||||
|
|
||||||
useSpaceSSE({
|
const onEvent = useCallback(
|
||||||
space,
|
data => {
|
||||||
events: ['execution_updated', 'execution_completed', 'execution_canceled', 'execution_running'],
|
// should I include pipeline id here? what if a new pipeline is created? could check for ids that are higher than the lowest id on the page?
|
||||||
onEvent: data => {
|
if (repoMetadata?.id === data?.repo_id) {
|
||||||
// should I include pipeline id here? what if a new pipeline is created? coould check for ids that are higher than the lowest id on the page?
|
//TODO - revisit full refresh - can I use the message to update the pipeline?
|
||||||
if (pipelines?.some(pipeline => pipeline.repo_id === data?.repo_id && pipeline.id === data?.pipeline_id)) {
|
|
||||||
//TODO - revisit full refresh - can I use the message to update the execution?
|
|
||||||
pipelinesRefetch()
|
pipelinesRefetch()
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
[repoMetadata?.id]
|
||||||
|
)
|
||||||
|
|
||||||
|
const events = useMemo(
|
||||||
|
() => ['execution_updated', 'execution_completed', 'execution_canceled', 'execution_running'],
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
|
||||||
|
useSpaceSSE({
|
||||||
|
space,
|
||||||
|
events,
|
||||||
|
onEvent
|
||||||
})
|
})
|
||||||
|
|
||||||
const NewPipelineButton = (
|
const NewPipelineButton = (
|
||||||
@ -300,6 +311,7 @@ const PipelineList = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
[getString, history, repoMetadata?.path, routes, searchTerm]
|
[getString, history, repoMetadata?.path, routes, searchTerm]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -311,7 +323,7 @@ const PipelineList = () => {
|
|||||||
dataTooltipId="repositoryPipelines"
|
dataTooltipId="repositoryPipelines"
|
||||||
/>
|
/>
|
||||||
<PageBody
|
<PageBody
|
||||||
className={cx({ [css.withError]: !!error })}
|
className={cx({ [css.withError]: !!error || !!pipelinesError })}
|
||||||
error={error || pipelinesError ? getErrorMessage(error || pipelinesError) : null}
|
error={error || pipelinesError ? getErrorMessage(error || pipelinesError) : null}
|
||||||
retryOnError={voidFn(refetch)}
|
retryOnError={voidFn(refetch)}
|
||||||
noData={{
|
noData={{
|
||||||
|
@ -61,16 +61,25 @@ export default function RepositoriesListing() {
|
|||||||
queryParams: { page, limit: LIST_FETCHING_LIMIT, query: searchTerm },
|
queryParams: { page, limit: LIST_FETCHING_LIMIT, query: searchTerm },
|
||||||
debounce: 500
|
debounce: 500
|
||||||
})
|
})
|
||||||
useSpaceSSE({
|
|
||||||
space,
|
const onEvent = useCallback(
|
||||||
events: ['repository_import_completed'],
|
data => {
|
||||||
onEvent: data => {
|
// should I include repo id here? what if a new repo is created? coould check for ids that are higher than the lowest id on the page?
|
||||||
// should I include pipeline id here? what if a new pipeline is created? coould check for ids that are higher than the lowest id on the page?
|
|
||||||
if (repositories?.some(repository => repository.id === data?.id && repository.parent_id === data?.parent_id)) {
|
if (repositories?.some(repository => repository.id === data?.id && repository.parent_id === data?.parent_id)) {
|
||||||
//TODO - revisit full refresh - can I use the message to update the execution?
|
//TODO - revisit full refresh - can I use the message to update the execution?
|
||||||
refetch()
|
refetch()
|
||||||
}
|
}
|
||||||
}
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
},
|
||||||
|
[repositories]
|
||||||
|
)
|
||||||
|
|
||||||
|
const events = useMemo(() => ['repository_import_completed'], [])
|
||||||
|
|
||||||
|
useSpaceSSE({
|
||||||
|
space,
|
||||||
|
events,
|
||||||
|
onEvent
|
||||||
})
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect, useState } from 'react'
|
import React, { useEffect, useMemo, useState } from 'react'
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Text,
|
Text,
|
||||||
@ -18,8 +18,8 @@ import { useMutate, useGet } from 'restful-react'
|
|||||||
import { Intent, Color, FontVariation } from '@harnessio/design-system'
|
import { Intent, Color, FontVariation } from '@harnessio/design-system'
|
||||||
import { useHistory } from 'react-router-dom'
|
import { useHistory } from 'react-router-dom'
|
||||||
import { Dialog } from '@blueprintjs/core'
|
import { Dialog } from '@blueprintjs/core'
|
||||||
import { useGetRepositoryMetadata } from 'hooks/useGetRepositoryMetadata'
|
|
||||||
import { ProgressBar, Intent as IntentCore } from '@blueprintjs/core'
|
import { ProgressBar, Intent as IntentCore } from '@blueprintjs/core'
|
||||||
|
import { useGetRepositoryMetadata } from 'hooks/useGetRepositoryMetadata'
|
||||||
import { TypesJobProgress, useGetSpace } from 'services/code'
|
import { TypesJobProgress, useGetSpace } from 'services/code'
|
||||||
import { useAppContext } from 'AppContext'
|
import { useAppContext } from 'AppContext'
|
||||||
import { useStrings } from 'framework/strings'
|
import { useStrings } from 'framework/strings'
|
||||||
@ -86,9 +86,11 @@ export default function SpaceSettings() {
|
|||||||
}
|
}
|
||||||
}, [exportProgressSpace, checkExportIsRunning, checkReposState, countFinishedRepos])
|
}, [exportProgressSpace, checkExportIsRunning, checkReposState, countFinishedRepos])
|
||||||
|
|
||||||
|
const events = useMemo(() => ['repository_export_completed'], [])
|
||||||
|
|
||||||
useSpaceSSE({
|
useSpaceSSE({
|
||||||
space,
|
space,
|
||||||
events: ['repository_export_completed'],
|
events,
|
||||||
onEvent: () => {
|
onEvent: () => {
|
||||||
refetchExport()
|
refetchExport()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user