Skip to content

Commit

Permalink
Debounce autoreload of non web servers during development
Browse files Browse the repository at this point in the history
  • Loading branch information
medihack committed Nov 14, 2023
1 parent cf8797f commit 9052efd
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
## Top

- Before new release
-- Fix order of forms that source / destination fields are at the top again
-- test job_utils
-- exclude autoreload when tests are saved (Custom Filter in server command watched files)
-- Test canceled task/job in test_workers.py
Expand Down Expand Up @@ -112,6 +111,7 @@

## Maybe

- Switch from Daphne to Uvicorn (maybe it has faster restart times during development)
- Switch from Celery to Huey
- Upgrade postgres server to v15, but we have to migrate the data then as the database files are incompatible a newer version
-- <https://hollo.me/devops/upgrade-postgresql-database-with-docker.html>
Expand Down
4 changes: 4 additions & 0 deletions adit/core/management/base/server_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from django.core.management.base import BaseCommand
from watchfiles import PythonFilter, watch

from ...utils.debounce import debounce


class ServerCommand(BaseCommand, ABC):
"""See Django's runserver.py command.
Expand Down Expand Up @@ -57,6 +59,8 @@ def run(self, **options):
if options["autoreload"]:
self.stdout.write(f"Autoreload enabled for {self.server_name}.")

# We debounce to give the Django webserver time to restart first
@debounce(wait_time=2)
def inner_run():
if self._popen is not None:
self._popen.terminate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
def debounce(wait_time=1):
"""Decorator that will debounce a function.
#
Function is called after wait_time in seconds. If it is called multiple times,
it will wait for the last call to be debounced and run only this one.
"""
Expand Down
2 changes: 1 addition & 1 deletion adit/selective_transfer/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

from adit.accounts.models import User
from adit.core.models import DicomNode
from adit.core.utils.debounce import debounce
from adit.core.utils.dicom_dataset import QueryDataset, ResultDataset
from adit.core.utils.dicom_operator import DicomOperator
from adit.core.utils.job_utils import queue_pending_tasks

from .forms import SelectiveTransferJobForm
from .models import SelectiveTransferJob, SelectiveTransferTask
from .utils.debounce import debounce
from .views import SELECTIVE_TRANSFER_ADVANCED_OPTIONS_COLLAPSED

logger = logging.getLogger(__name__)
Expand Down

0 comments on commit 9052efd

Please sign in to comment.