Skip to content

Commit

Permalink
🪟 🐛 Correct connection overview status to not pull from an active job…
Browse files Browse the repository at this point in the history
… (#6426)

Co-authored-by: Vladimir <dizel852@gmail.com>
  • Loading branch information
chandlerprall and dizel852 committed May 12, 2023
1 parent e168500 commit 7d0985d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,19 @@ interface ConnectionSyncContext {
resetStarting: boolean;
jobResetRunning: boolean;
activeJob?: JobRead;
lastCompletedSyncJob?: JobWithAttemptsRead;
connectionStatus: ConnectionSyncStatus;
latestSyncJobCreatedAt?: JobCreatedAt;
nextSync?: dayjs.Dayjs;
lastSuccessfulSync?: number;
}

const jobStatusesIndicatingFinishedExecution: string[] = [
JobStatus.cancelled,
JobStatus.succeeded,
JobStatus.failed,
JobStatus.incomplete,
];
const useConnectionSyncContextInit = (jobs: JobWithAttemptsRead[]): ConnectionSyncContext => {
const { connection } = useConnectionEditService();
const [activeJob, setActiveJob] = useState(jobs[0]?.job);
Expand Down Expand Up @@ -83,10 +90,14 @@ const useConnectionSyncContextInit = (jobs: JobWithAttemptsRead[]): ConnectionSy
[activeJob?.configType, activeJob?.status]
);

const lastSyncJob = jobs.find(({ job }) => job?.configType === JobConfigType.sync);
const lastSyncJobStatus = lastSyncJob?.job?.status || connection.latestSyncJobStatus;
const lastCompletedSyncJob = jobs.find(
({ job }) =>
job && job.configType === JobConfigType.sync && jobStatusesIndicatingFinishedExecution.includes(job.status)
);
const lastSyncJobStatus = lastCompletedSyncJob?.job?.status || connection.latestSyncJobStatus;
const connectionStatus = getConnectionSyncStatus(connection.status, lastSyncJobStatus);

const lastSyncJob = jobs.find(({ job }) => job?.configType === JobConfigType.sync);
const latestSyncJobCreatedAt = lastSyncJob?.job?.createdAt;

const lastSuccessfulSyncJob = jobs.find(
Expand Down Expand Up @@ -115,6 +126,7 @@ const useConnectionSyncContextInit = (jobs: JobWithAttemptsRead[]): ConnectionSy
resetStarting,
jobResetRunning,
activeJob,
lastCompletedSyncJob,
connectionStatus,
latestSyncJobCreatedAt,
nextSync,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const isConnectionLate = (
);
};

const useConnectionStatus = () => {
export const useConnectionStatus = () => {
const lateMultiplier = useLateMultiplierExperiment();
const errorMultiplier = useErrorMultiplierExperiment();

Expand All @@ -85,7 +85,8 @@ const useConnectionStatus = () => {
!hasBreakingSchemaChange &&
connectionStatus === ConnectionSyncStatus.FAILED &&
(isUnscheduledConnection(connection.scheduleType) ||
isConnectionLate(connection, lastSuccessfulSync, errorMultiplier))
isConnectionLate(connection, lastSuccessfulSync, errorMultiplier) ||
lastSuccessfulSync == null) // edge case: if the number of jobs we have loaded isn't enough to find the last successful sync
) {
return ConnectionStatusIndicatorStatus.Error;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ export const ErrorMessage: React.FC = () => {
const navigate = useNavigate();
const { formatMessage } = useIntl();

const { jobs } = useStreamsListContext();

const { connection } = useConnectionEditService();
const { lastCompletedSyncJob } = useConnectionSyncContext();
const { hasSchemaChanges, hasBreakingSchemaChange } = useSchemaChanges(connection.schemaChange);

const calloutDetails = useMemo<{
Expand All @@ -46,8 +45,8 @@ export const ErrorMessage: React.FC = () => {
buttonMessage: string;
variant: "error" | "info";
} | null>(() => {
const { jobId, attemptId, errorMessage } = getErrorMessageFromJob(jobs?.[0]) ?? {};
// If we have an error message and a non-breaking schema change, show the error message
const { jobId, attemptId, errorMessage } = getErrorMessageFromJob(lastCompletedSyncJob) ?? {};
// If we have an error message and no breaking schema changes, show the error message
if (errorMessage && !hasBreakingSchemaChange) {
return {
errorMessage,
Expand All @@ -71,7 +70,7 @@ export const ErrorMessage: React.FC = () => {
}

return null;
}, [formatMessage, hasBreakingSchemaChange, hasSchemaChanges, jobs, navigate]);
}, [formatMessage, hasBreakingSchemaChange, hasSchemaChanges, lastCompletedSyncJob, navigate]);

if (calloutDetails) {
return (
Expand Down

0 comments on commit 7d0985d

Please sign in to comment.