Skip to content

Support windows #13

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

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
70e2cf5
support windows
olivierdalang Jan 23, 2023
1722112
support windows followup
olivierdalang Jan 23, 2023
5a044a7
support windows followup
olivierdalang Jan 23, 2023
ab1f446
support windows followup
olivierdalang Jan 23, 2023
7bcf5fe
(update readme)
olivierdalang Feb 23, 2023
273eb9d
Merge branch 'master' into support-windows
olivierdalang Feb 23, 2023
0a3839a
(style)
olivierdalang Feb 23, 2023
ba4d579
cleanup dockerfile
olivierdalang Feb 23, 2023
0befda9
try to fix win build
olivierdalang Feb 23, 2023
1799052
try to workaround empty envar
olivierdalang Feb 23, 2023
f312843
try to workaround empty envar still
olivierdalang Feb 23, 2023
c71fc3f
try to workaround empty envar still
olivierdalang Feb 23, 2023
f86ff2e
native windows
olivierdalang Feb 23, 2023
0d85754
fix ci?
olivierdalang Apr 7, 2023
5c49d90
skip graceful exit
olivierdalang Apr 7, 2023
7c1d54d
Merge branch 'master' of git@github.com:olivierdalang/django-toosimpl…
olivierdalang Nov 2, 2023
c59fdd5
Merge branch 'master' of git@github.com:olivierdalang/django-toosimpl…
olivierdalang Dec 4, 2023
22c1e33
ci: try to fix windows workflow
olivierdalang Dec 4, 2023
27dd29d
ci: try to fix windows workflow
olivierdalang Dec 4, 2023
f19af8a
ci: try to fix windows workflow
olivierdalang Dec 4, 2023
a81bca1
ci: try to fix windows workflow
olivierdalang Dec 4, 2023
8ef82eb
fix invalid version with recent setuptools
olivierdalang Dec 4, 2023
b371f27
fix: fix last_task not populated
olivierdalang Jan 15, 2024
88cbb2a
Merge branch 'master' into support-windows
olivierdalang Feb 13, 2024
28f77da
Merge branch 'master' into support-windows
olivierdalang Mar 4, 2024
051d329
Merge branch 'master' into support-windows
olivierdalang Mar 7, 2024
5eeebe1
Merge branch 'master' into support-windows
olivierdalang Mar 7, 2024
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
31 changes: 30 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
pull_request:

jobs:
test:
test-docker:
name: Tests dj${{ matrix.dj }} / ${{ matrix.db }} / py${{ matrix.py }}

runs-on: ubuntu-latest
Expand Down Expand Up @@ -47,3 +47,32 @@ jobs:

- name: Run tests
run: docker compose run django test

test-windows:
name: Tests windows

runs-on: windows-latest

steps:
- uses: actions/checkout@v2

- name: Python version
run: python --version

- name: Packages versions
run: pip freeze --all

- name: Setup postgres
uses: ikalnytskyi/action-setup-postgres@v4

- name: Update pip
run: pip install --upgrade pip setuptools

- name: Install python deps
run: pip install -r requirements-dev.txt

- name: Run tests
env:
TOOSIMPLEQ_TEST_DB: postgres
POSTGRES_PORT_WORKER: "5432"
run: python manage.py test
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ pre-commit install
- feature: added workerstatus to the admin, allowing to monitor workers
- feature: queue tasks for later (`mytask.queue(due=now()+timedelta(hours=2))`)
- feature: assign queues to schedules (`@schedule_task(queue="schedules")`)
- feature: support windows
- feature: allow manual schedules that are only run manually through the admin (`@schedule_task(cron="manual")`)
- refactor: removed non-execution related data from the database (clarifying the fact tha the source of truth is the registry)
- refactor: better support for concurrent workers
Expand Down
6 changes: 4 additions & 2 deletions django_toosimple_q/management/commands/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ def handle(self, *args, **options):
signal.signal(signal.SIGINT, self.handle_signal)
signal.signal(signal.SIGTERM, self.handle_signal)
# Custom signal to provoke an artifical exception, used for testing only
signal.signal(signal.SIGUSR1, self.handle_signal)
if hasattr(signal, "SIGUSR1"):
# this doesn't exist on Windows
signal.signal(signal.SIGUSR1, self.handle_signal)

# TODO: replace by simple-parsing
self.queues = options["queue"] or []
Expand Down Expand Up @@ -248,7 +250,7 @@ def do_loop(self) -> bool:

def handle_signal(self, sig, stackframe):
# For testing, simulates a unexpected crash of the worker
if sig == signal.SIGUSR1:
if hasattr(signal, "SIGUSR1") and sig == signal.SIGUSR1:
self.simulate_exception = True
return

Expand Down
14 changes: 9 additions & 5 deletions django_toosimple_q/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def start_worker_in_background(
env={**os.environ, "DJANGO_SETTINGS_MODULE": settings},
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=(os.name == "nt"), # for some reason this seems needed on windows
)
)

Expand All @@ -182,11 +183,14 @@ def wait_for_qs(self, queryset, exists=True, timeout=15):

def wait_for_tasks(self, timeout=15):
"""Waits untill all tasks are marked as done in the database"""
return self.wait_for_qs(
TaskExec.objects.filter(state__in=TaskExec.States.todo()),
exists=False,
timeout=timeout,
)
try:
return self.wait_for_qs(
TaskExec.objects.filter(state__in=TaskExec.States.todo()),
exists=False,
timeout=timeout,
)
except AssertionError:
self.workers_get_stdout()

def workers_get_stdout(self):
"""Stops the workers if needed and returns the stdout of the last worker, or raises an exception on error.
Expand Down
14 changes: 13 additions & 1 deletion django_toosimple_q/tests/tests_worker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import signal
import time
import unittest

from django.core import management
from freezegun import freeze_time
Expand Down Expand Up @@ -70,7 +72,11 @@ def _start_worker_with_task(self, duration=10):
)

# Wait for the task to be picked up by the worker
self.wait_for_qs(TaskExec.objects.filter(state=TaskExec.States.PROCESSING))
try:
self.wait_for_qs(TaskExec.objects.filter(state=TaskExec.States.PROCESSING))
except AssertionError:
# Show the error
self.workers_get_stdout()

# Keep id of the first task for further reference
self.__first_task_pk = TaskExec.objects.first().pk
Expand Down Expand Up @@ -140,6 +146,9 @@ def test_terminate(self):
self.assertIsNotNone(self.taskexec.replaced_by)
self.assertEqual(self.taskexec.replaced_by.state, TaskExec.States.SLEEPING)

@unittest.skipIf(
not hasattr(signal, "SIGUSR1"), "USR1 signal not available on this platform"
)
def test_worker_crash(self):
self._start_worker_with_task()

Expand All @@ -156,6 +165,9 @@ def test_worker_crash(self):

# The failure is not linked to the task

@unittest.skipIf(
os.name == "nt", "didn't find a way to gracefully stop subprocess on windows"
)
def test_quit(self):
self._start_worker_with_task()

Expand Down