Skip to content

Commit

Permalink
Fixed 'database is locked' error.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeRomaa committed Mar 10, 2021
1 parent 4beeaa4 commit 8df3b4d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
18 changes: 9 additions & 9 deletions apps/tmu/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ def fetch_metars():
for airport in airports_icao:
url = 'https://avwx.rest/api/metar/' + airport + '?format=json&onfail=cache'
resp = requests.get(url, headers=headers)

data = resp.json()

METAR.objects.update_or_create(
station=data.get('station'),
defaults={
'raw': data.get('sanitized'),
'flight_rules': data.get('flight_rules'),
'timestamp': pytz.utc.localize(datetime.fromisoformat(data.get('time').get('dt')[:-1])),
}
)
query = METAR.objects.filter(station=airport)
if query.exists():
query.delete()

METAR(
raw=data.get('sanitized'),
flight_rules=data.get('flight_rules'),
timestamp=pytz.utc.localize(datetime.fromisoformat(data.get('time').get('dt')[:-1])),
).save()
16 changes: 8 additions & 8 deletions zhu_core/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,32 @@ def start_scheduler():

scheduler.add_job(
users.sync_vatusa_roster,
trigger=CronTrigger(minute=0), # Top of every hour
trigger=CronTrigger(minute=1), # Top of every hour + 1
id='sync_vatusa_roster',
max_instances=1,
replace_existing=True,
)

scheduler.add_job(
users.update_user_ratings,
trigger=CronTrigger(minute=0), # Top of every hour
trigger=CronTrigger(minute=2), # Top of every hour + 2
id='update_user_ratings',
max_instances=1,
replace_existing=True,
)

scheduler.add_job(
tmu.delete_inactive_atis,
trigger=CronTrigger(minute=0), # Top of every hour
id='delete_inactive_atis',
tmu.fetch_metars,
trigger=CronTrigger(minute=3), # Top of every hour + 3
id='fetch_metars',
max_instances=1,
replace_existing=True,
)

scheduler.add_job(
tmu.fetch_metars,
trigger=CronTrigger(minute=0), # Top of every hour
id='fetch_metars',
tmu.delete_inactive_atis,
trigger=CronTrigger(minute=4), # Top of every hour + 4
id='delete_inactive_atis',
max_instances=1,
replace_existing=True,
)
Expand Down
3 changes: 3 additions & 0 deletions zhu_core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
'OPTIONS': {
'timeout': 20,
}
}
}

Expand Down

0 comments on commit 8df3b4d

Please sign in to comment.