-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change way periodic tasks are launched
- Loading branch information
Showing
11 changed files
with
221 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.core.management import BaseCommand | ||
from django_geosource.periodics import auto_refresh_source | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Launch resync of all sources if needed" | ||
|
||
def handle(self, *args, **options): | ||
auto_refresh_source() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 3.1.4 on 2021-09-08 15:29 | ||
|
||
from django.db import migrations, models | ||
import django.utils.timezone | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("django_geosource", "0020_auto_20201008_0851"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="source", | ||
name="last_refresh", | ||
field=models.DateTimeField(default=django.utils.timezone.now), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import logging | ||
from django_geosource.models import Source | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def auto_refresh_source(): | ||
countdown = 0 | ||
for source in Source.objects.all(): | ||
logger.info(f"Is refresh for {source}<{source.id}> needed?") | ||
if source.should_refresh(): | ||
logger.info(f"Schedule refresh for source {source}<{source.id}>...") | ||
# Delay execution by some minutes to avoid struggling | ||
try: | ||
source.run_async_method("refresh_data", countdown=countdown, force=True) | ||
countdown += 60 * 3 | ||
except Exception: | ||
logger.exception("Failed to refresh source!") |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.