Skip to content

Commit 0ac39ed

Browse files
committed
Replace "autotask" with "autocron"
1 parent 9be2686 commit 0ac39ed

File tree

6 files changed

+50
-42
lines changed

6 files changed

+50
-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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
:license: GNU GPL v3 or above, see LICENSE for more details.
77
"""
88

9-
9+
import autocron
1010
from django.apps import AppConfig
1111

1212

@@ -16,3 +16,5 @@ class ForRunnersConfig(AppConfig):
1616

1717
def ready(self):
1818
import for_runners.checks # noqa
19+
20+
autocron.start('autocron.db') # 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
@@ -111,6 +111,10 @@ attrs==23.2.0 \
111111
# aiohttp
112112
# cmd2
113113
# flake8-bugbear
114+
autocron==0.9.2 \
115+
--hash=sha256:763f98b8245eaf1b4519f506aa27eeffd36d0947fe1d89382751bcc14b7d08b2 \
116+
--hash=sha256:e29ff5f117fcf6f53e78d41dd775a5dfdf860731fc845ccdb3be776a492e8f93
117+
# via django-for-runners (pyproject.toml)
114118
autoflake==2.2.1 \
115119
--hash=sha256:265cde0a43c1f44ecfb4f30d95b0437796759d07be7706a2f70e4719234c0f79 \
116120
--hash=sha256:62b7b6449a692c3c9b0c916919bbc21648da7281e8506bcf8d3f8280e431ebc1
@@ -121,9 +125,6 @@ autopep8==2.0.4 \
121125
# via
122126
# django-for-runners (pyproject.toml)
123127
# manageprojects
124-
autotask==0.5.4 \
125-
--hash=sha256:d21578ab14adafb0d9be3490a444d261fd2bcdcbb1ee941b28d4b5e5d1a386ad
126-
# via django-for-runners (pyproject.toml)
127128
binaryornot==0.4.4 \
128129
--hash=sha256:359501dfc9d40632edc9fac890e19542db1a287bbcfa58175b66658392018061 \
129130
--hash=sha256:b8b71173c917bddcd2c16070412e369c3ed7f0528926f70cac18a6c97fd563e4

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ asgiref==3.7.2 \
88
--hash=sha256:89b2ef2247e3b562a16eef663bc0e2e703ec6468e2fa8a5cd61cd449786d4f6e \
99
--hash=sha256:9e0ce3aa93a819ba5b45120216b23878cf6e8525eb3848653452b4192b92afed
1010
# via django
11-
autotask==0.5.4 \
12-
--hash=sha256:d21578ab14adafb0d9be3490a444d261fd2bcdcbb1ee941b28d4b5e5d1a386ad
11+
autocron==0.9.2 \
12+
--hash=sha256:763f98b8245eaf1b4519f506aa27eeffd36d0947fe1d89382751bcc14b7d08b2 \
13+
--hash=sha256:e29ff5f117fcf6f53e78d41dd775a5dfdf860731fc845ccdb3be776a492e8f93
1314
# via django-for-runners (pyproject.toml)
1415
bleach==6.1.0 \
1516
--hash=sha256:0a31f1837963c41d46bbf1331b8778e1308ea0791db03cc4e7357b97cf42a8fe \

0 commit comments

Comments
 (0)