Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace "autotask" with "autocron" #108

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ __pycache__
# Django
secret.txt

# Autocron own SQLite database file:
autocron.db
10 changes: 9 additions & 1 deletion for_runners/apps.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
from pathlib import Path

import autocron
from django.apps import AppConfig as BaseAppConfig


class AppConfig(BaseAppConfig):
name = 'for_runners'
verbose_name = "ForRunners"
verbose_name = 'ForRunners'

def ready(self):
import for_runners.checks # noqa

# TODO: Remove after: https://github.com/kbr/autocron/issues/3
Path('~/.autocron').expanduser().mkdir(parents=True, exist_ok=True)

autocron.start('for_runner_autocron.sqlite') # activate autocron with his SQLite database
72 changes: 37 additions & 35 deletions for_runners/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,40 @@
:license: GNU GPL v3 or above, see LICENSE for more details.
"""

# import io
# import logging
#
# from autotask.tasks import delayed_task
# from for_runners.gpx_tools.garmin2gpxpy import garmin2gpxpy
#
#
# log = logging.getLogger(__name__)
#
#
# @delayed_task()
# def generate_gpx_map_task(object_id):
# """
# Delayed task to generate the map from GPX track
# """
# log.debug("Generate GPX Map for ID: %r", object_id)
#
# from for_runners.models import GpxModel # import here, because of import-loop
# gpx_instance = GpxModel.objects.get(pk=object_id)
# log.info("Generate GPX Map for: %s" % gpx_instance)
#
# content = gpx_instance.gpx
# gpxpy_instance = garmin2gpxpy(content)
#
# image, plt = generate_map(gpxpy_instance)
#
# temp = io.BytesIO()
# plt.savefig(temp, bbox_inches="tight")
#
# filename = "%s.png" % gpx_instance.get_short_slug()
#
# # Save gpx map file to model instance:
# gpx_instance.map_image.save(filename, temp)
#
# log.info("GPX data saved to %s, ok." % gpx_instance)
import io
import logging

import autocron

from for_runners.gpx_tools.garmin2gpxpy import garmin2gpxpy


log = logging.getLogger(__name__)


@autocron.delay
def generate_gpx_map_task(object_id):
"""
Delayed task to generate the map from GPX track
"""
log.debug("Generate GPX Map for ID: %r", object_id)

from for_runners.models import GpxModel # import here, because of import-loop

gpx_instance = GpxModel.objects.get(pk=object_id)
log.info(f"Generate GPX Map for: {gpx_instance}")

content = gpx_instance.gpx
gpxpy_instance = garmin2gpxpy(content)

image, plt = generate_map(gpxpy_instance)

temp = io.BytesIO()
plt.savefig(temp, bbox_inches="tight")

filename = f"{gpx_instance.get_short_slug()}.png"

# Save gpx map file to model instance:
gpx_instance.map_image.save(filename, temp)

log.info(f"GPX data saved to {gpx_instance}, ok.")
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies = [
"django-tools", # https://github.com/jedie/django-tools/
"django-import-export", # https://github.com/django-import-export/django-import-export
"django-admin-sortable2", # https://github.com/jrief/django-admin-sortable2
"autotask", # https://github.com/kbr/autotask
"autocron", # https://github.com/kbr/autocron
"gpxpy", # https://github.com/tkrajina/gpxpy
"matplotlib", # http://matplotlib.org/
"svgwrite", # http://github.com/mozman/svgwrite.git
Expand Down
7 changes: 4 additions & 3 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ authlib==1.3.1 \
--hash=sha256:7ae843f03c06c5c0debd63c9db91f9fda64fa62a42a77419fa15fbb7e7a58917 \
--hash=sha256:d35800b973099bbadc49b42b256ecb80041ad56b7fe1216a362c7943c088f377
# via safety
autocron==1.0 \
--hash=sha256:4c3624308ccfd8f05c3ff4f09f4b87c3c5edffbcc1975ee839945b17ea69a65b \
--hash=sha256:db73b7b5a10359d88cc2e68c8709ba0abacad36fd3846b579899a423f1b1e66a
# via django-for-runners (pyproject.toml)
autoflake==2.3.1 \
--hash=sha256:3ae7495db9084b7b32818b4140e6dc4fc280b712fb414f5b8fe57b0a8e85a840 \
--hash=sha256:c98b75dc5b0a86459c4f01a1d32ac7eb4338ec4317a4469515ff1e687ecd909e
Expand All @@ -48,9 +52,6 @@ autopep8==2.3.1 \
# via
# django-for-runners (pyproject.toml)
# manageprojects
autotask==0.5.4 \
--hash=sha256:d21578ab14adafb0d9be3490a444d261fd2bcdcbb1ee941b28d4b5e5d1a386ad
# via django-for-runners (pyproject.toml)
backports-tarfile==1.2.0 \
--hash=sha256:77e284d754527b01fb1e6fa8a1afe577858ebe4e9dad8919e34c862cb399bc34 \
--hash=sha256:d75e02c268746e1b8144c278978b6e98e85de6ad16f8e4b0844a154557eca991
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ attrs==23.2.0 \
# via
# cattrs
# requests-cache
autotask==0.5.4 \
--hash=sha256:d21578ab14adafb0d9be3490a444d261fd2bcdcbb1ee941b28d4b5e5d1a386ad
autocron==1.0 \
--hash=sha256:4c3624308ccfd8f05c3ff4f09f4b87c3c5edffbcc1975ee839945b17ea69a65b \
--hash=sha256:db73b7b5a10359d88cc2e68c8709ba0abacad36fd3846b579899a423f1b1e66a
# via django-for-runners (pyproject.toml)
bleach==6.1.0 \
--hash=sha256:0a31f1837963c41d46bbf1331b8778e1308ea0791db03cc4e7357b97cf42a8fe \
Expand Down
Loading