Skip to content

Commit 0ee151d

Browse files
committed
Replace "autotask" with "autocron"
1 parent 0c86f55 commit 0ee151d

File tree

6 files changed

+56
-42
lines changed

6 files changed

+56
-42
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ __pycache__
2828
# Django
2929
secret.txt
3030

31+
# Autocron own SQLite database file:
32+
autocron.db

for_runners/apps.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
from pathlib import Path
2+
3+
import autocron
14
from django.apps import AppConfig as BaseAppConfig
25

36

47
class AppConfig(BaseAppConfig):
58
name = 'for_runners'
6-
verbose_name = "ForRunners"
9+
verbose_name = 'ForRunners'
710

811
def ready(self):
912
import for_runners.checks # noqa
13+
14+
# TODO: Remove after: https://github.com/kbr/autocron/issues/3
15+
Path('~/.autocron').expanduser().mkdir(parents=True, exist_ok=True)
16+
17+
autocron.start('for_runner_autocron.sqlite') # activate autocron with his SQLite database

for_runners/tasks.py

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,40 @@
44
:license: GNU GPL v3 or above, see LICENSE for more details.
55
"""
66

7-
# import io
8-
# import logging
9-
#
10-
# from autotask.tasks import delayed_task
11-
# from for_runners.gpx_tools.garmin2gpxpy import garmin2gpxpy
12-
#
13-
#
14-
# log = logging.getLogger(__name__)
15-
#
16-
#
17-
# @delayed_task()
18-
# def generate_gpx_map_task(object_id):
19-
# """
20-
# Delayed task to generate the map from GPX track
21-
# """
22-
# log.debug("Generate GPX Map for ID: %r", object_id)
23-
#
24-
# from for_runners.models import GpxModel # import here, because of import-loop
25-
# gpx_instance = GpxModel.objects.get(pk=object_id)
26-
# log.info("Generate GPX Map for: %s" % gpx_instance)
27-
#
28-
# content = gpx_instance.gpx
29-
# gpxpy_instance = garmin2gpxpy(content)
30-
#
31-
# image, plt = generate_map(gpxpy_instance)
32-
#
33-
# temp = io.BytesIO()
34-
# plt.savefig(temp, bbox_inches="tight")
35-
#
36-
# filename = "%s.png" % gpx_instance.get_short_slug()
37-
#
38-
# # Save gpx map file to model instance:
39-
# gpx_instance.map_image.save(filename, temp)
40-
#
41-
# log.info("GPX data saved to %s, ok." % gpx_instance)
7+
import io
8+
import logging
9+
10+
import autocron
11+
12+
from for_runners.gpx_tools.garmin2gpxpy import garmin2gpxpy
13+
14+
15+
log = logging.getLogger(__name__)
16+
17+
18+
@autocron.delay
19+
def generate_gpx_map_task(object_id):
20+
"""
21+
Delayed task to generate the map from GPX track
22+
"""
23+
log.debug("Generate GPX Map for ID: %r", object_id)
24+
25+
from for_runners.models import GpxModel # import here, because of import-loop
26+
27+
gpx_instance = GpxModel.objects.get(pk=object_id)
28+
log.info(f"Generate GPX Map for: {gpx_instance}")
29+
30+
content = gpx_instance.gpx
31+
gpxpy_instance = garmin2gpxpy(content)
32+
33+
image, plt = generate_map(gpxpy_instance)
34+
35+
temp = io.BytesIO()
36+
plt.savefig(temp, bbox_inches="tight")
37+
38+
filename = f"{gpx_instance.get_short_slug()}.png"
39+
40+
# Save gpx map file to model instance:
41+
gpx_instance.map_image.save(filename, temp)
42+
43+
log.info(f"GPX data saved to {gpx_instance}, ok.")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dependencies = [
1919
"django-tools", # https://github.com/jedie/django-tools/
2020
"django-import-export", # https://github.com/django-import-export/django-import-export
2121
"django-admin-sortable2", # https://github.com/jrief/django-admin-sortable2
22-
"autotask", # https://github.com/kbr/autotask
22+
"autocron", # https://github.com/kbr/autocron
2323
"gpxpy", # https://github.com/tkrajina/gpxpy
2424
"matplotlib", # http://matplotlib.org/
2525
"svgwrite", # http://github.com/mozman/svgwrite.git

requirements.dev.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ authlib==1.3.1 \
3838
--hash=sha256:7ae843f03c06c5c0debd63c9db91f9fda64fa62a42a77419fa15fbb7e7a58917 \
3939
--hash=sha256:d35800b973099bbadc49b42b256ecb80041ad56b7fe1216a362c7943c088f377
4040
# via safety
41+
autocron==1.0 \
42+
--hash=sha256:4c3624308ccfd8f05c3ff4f09f4b87c3c5edffbcc1975ee839945b17ea69a65b \
43+
--hash=sha256:db73b7b5a10359d88cc2e68c8709ba0abacad36fd3846b579899a423f1b1e66a
44+
# via django-for-runners (pyproject.toml)
4145
autoflake==2.3.1 \
4246
--hash=sha256:3ae7495db9084b7b32818b4140e6dc4fc280b712fb414f5b8fe57b0a8e85a840 \
4347
--hash=sha256:c98b75dc5b0a86459c4f01a1d32ac7eb4338ec4317a4469515ff1e687ecd909e
@@ -48,9 +52,6 @@ autopep8==2.3.1 \
4852
# via
4953
# django-for-runners (pyproject.toml)
5054
# manageprojects
51-
autotask==0.5.4 \
52-
--hash=sha256:d21578ab14adafb0d9be3490a444d261fd2bcdcbb1ee941b28d4b5e5d1a386ad
53-
# via django-for-runners (pyproject.toml)
5455
backports-tarfile==1.2.0 \
5556
--hash=sha256:77e284d754527b01fb1e6fa8a1afe577858ebe4e9dad8919e34c862cb399bc34 \
5657
--hash=sha256:d75e02c268746e1b8144c278978b6e98e85de6ad16f8e4b0844a154557eca991

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ attrs==23.2.0 \
1616
# via
1717
# cattrs
1818
# requests-cache
19-
autotask==0.5.4 \
20-
--hash=sha256:d21578ab14adafb0d9be3490a444d261fd2bcdcbb1ee941b28d4b5e5d1a386ad
19+
autocron==1.0 \
20+
--hash=sha256:4c3624308ccfd8f05c3ff4f09f4b87c3c5edffbcc1975ee839945b17ea69a65b \
21+
--hash=sha256:db73b7b5a10359d88cc2e68c8709ba0abacad36fd3846b579899a423f1b1e66a
2122
# via django-for-runners (pyproject.toml)
2223
bleach==6.1.0 \
2324
--hash=sha256:0a31f1837963c41d46bbf1331b8778e1308ea0791db03cc4e7357b97cf42a8fe \

0 commit comments

Comments
 (0)