improve geocoding

This commit is contained in:
orangecoding
2026-01-28 15:55:23 +01:00
parent 472169693f
commit 0b2b42fc75
10 changed files with 55 additions and 50 deletions

View File

@@ -1,29 +0,0 @@
/*
* Copyright (c) 2026 by Christian Kellner.
* Licensed under Apache-2.0 with Commons Clause and Attribution/Naming Clause
*/
import { removeJobsByUserId } from '../storage/jobStorage.js';
import { getUsers } from '../storage/userStorage.js';
import logger from '../logger.js';
import cron from 'node-cron';
import { getSettings } from '../storage/settingsStorage.js';
/**
* if we are running in demo environment, we have to cleanup the db files (specifically the jobs table)
*/
export function cleanupDemoAtMidnight() {
cron.schedule('0 0 * * *', cleanup);
}
async function cleanup() {
const settings = await getSettings();
if (settings.demoMode) {
const demoUser = getUsers(false).find((user) => user.username === 'demo');
if (demoUser == null) {
logger.error('Demo user not found, cannot remove Jobs');
return Promise.resolve();
}
removeJobsByUserId(demoUser.id);
}
}

View File

@@ -9,7 +9,7 @@ import { geocodeAddress, isGeocodingPaused } from '../geocoding/geoCodingService
import { getJobs } from '../storage/jobStorage.js';
import { calculateDistanceForJob } from '../geocoding/distanceService.js';
async function runTask() {
export async function runGeoCordTask() {
const listings = getListingsToGeocode();
if (listings.length > 0) {
for (const listing of listings) {
@@ -33,7 +33,7 @@ async function runTask() {
export async function initGeocodingCron() {
// run directly on start
await runTask();
await runGeoCordTask();
// then every 6 hours
cron.schedule('0 */6 * * *', runTask);
cron.schedule('0 */6 * * *', runGeoCordTask);
}