Skip to content

Commit fc5bae6

Browse files
committed
fix: properly abort, when flat is not found
1 parent bae4848 commit fc5bae6

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

app/actions/bot.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ export const navigateToFlatPage =
102102
);
103103
const flatTitleSelector = entryTitleSelector(flatId);
104104

105+
if (!(await puppetView.elementExists(flatTitleSelector))) {
106+
logger.warn(
107+
`Current flat with flatTitleSelector='${flatTitleSelector}' could not be found!`
108+
);
109+
logger.warn(`url:${puppetView.getURL()}`);
110+
dispatch(setBotMessage(`Fehler: Wohnung ${flatId} nicht gefunden...`));
111+
await sleep(5000);
112+
return false;
113+
}
114+
105115
/* eslint-disable no-await-in-loop */
106116
while (AbortionSystem.nestedFunctionsMayContinue) {
107117
if (!(await puppetView.elementExists(flatTitleSelector))) {

app/middleware/scheduler.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import type { Action, Dispatch, Store } from '../reducers/types';
22
import { LAUNCH_NEXT_TASK } from '../constants/actionTypes';
3-
import { navigateToFlatPage, noop, returnToSearchPage } from '../actions/bot';
3+
import {
4+
navigateToFlatPage,
5+
noop,
6+
returnToSearchPage,
7+
popFlatFromQueue
8+
} from '../actions/bot';
9+
import { markCompleted } from '../actions/cache';
410
import type { schedulerStateType } from '../reducers/scheduler';
11+
import { CacheNames } from '../reducers/cache';
512
import type { dataStateType } from '../reducers/data';
613
import { endApplicationProcess } from '../actions/application';
714
import { logger } from '../utils/tracer-logger.js';
@@ -52,6 +59,15 @@ export default (store: Store & { dispatch: Dispatch }) =>
5259
if (!reachedFlatPage) {
5360
// eslint-disable-next-line no-console
5461
logger.error(`Flat page wasn't reached, aborting task.`);
62+
await store.dispatch(popFlatFromQueue(nextFlatId));
63+
await store.dispatch(
64+
markCompleted(CacheNames.APPLICATIONS, nextFlatId, {
65+
flatId: nextFlatId,
66+
success: false,
67+
addressDescription: '',
68+
reason: 'Flat not found'
69+
})
70+
);
5571
store.dispatch(endApplicationProcess());
5672
}
5773

app/utils/electronUtils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ ${this.webContents.getURL()}`);
6363
.includes('immobilienscout24.de');
6464
}
6565

66+
getURL(): string {
67+
return this.webContents.getURL();
68+
}
69+
6670
static generateSelector(
6771
selector: string,
6872
shadowRootSelector?: string

0 commit comments

Comments
 (0)