Skip to content

Commit dfc31a2

Browse files
committed
fix too early persistence
1 parent 0a010de commit dfc31a2

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

content/academy/expert_scraping_with_apify/solutions/saving_stats.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ class Stats {
1919
errors: {},
2020
totalSaved: 0,
2121
};
22-
23-
Apify.events.on('persistState', async () => {
24-
await Apify.setValue('STATS', this.state);
25-
});
26-
27-
setInterval(() => console.log(this.state), 10000);
2822
}
2923

3024
async initialize() {
3125
const data = await Apify.getValue('STATS');
3226

3327
if (data) this.state = data;
28+
29+
Apify.events.on('persistState', async () => {
30+
await Apify.setValue('STATS', this.state);
31+
});
32+
33+
setInterval(() => console.log(this.state), 10000);
3434
}
3535

3636
addError(url, errorMessage) {

0 commit comments

Comments
 (0)