summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorMichael Hill <mhilluniversal@gmail.com>2022-03-09 20:04:24 -0500
committerGitHub <noreply@github.com>2022-03-10 08:04:24 +0700
commitf4602d30d5848ef688e26e453b883f546dc6d439 (patch)
tree874f6e5b4457461b6ab6c6c1542830ff89626bf2 /docs
parent609c068ef85c74c9a2e85f6b88138b2c3e9b9da5 (diff)
downloadrq-f4602d30d5848ef688e26e453b883f546dc6d439.tar.gz
Cross platform simple worker (#1629)
* Added CrossPlatformDeathPenalty that doesn't rely on signals * Updated `SimpleWorker`'s `death_penalty_class` to utilize `CrossPlatformDeathPenalty` to allow use on Windows machines * Changed `CrossPlatformDeathPenalty` to `TimerDeathPenalty` * Removed overridden `death_penalty_class` in `SimpleWorker` until feature matures * Added section in testing.md explaining how to utilize `SimpleWorker` on Windows OS * Replaced usage of chatting with .format for python 3.5 compatibility * Add tests for new timeout feature * Explicitly set defaults.CALLBACK_TIMEOUT * Implemented cross-thread method of raising errors by using ctypes * Finished writing tests for new TimerDeathPenalty
Diffstat (limited to 'docs')
-rw-r--r--docs/docs/testing.md21
1 files changed, 20 insertions, 1 deletions
diff --git a/docs/docs/testing.md b/docs/docs/testing.md
index 879e319..d340868 100644
--- a/docs/docs/testing.md
+++ b/docs/docs/testing.md
@@ -5,7 +5,7 @@ layout: docs
## Workers inside unit tests
-You may wish to include your RQ tasks inside unit tests. However many frameworks (such as Django) use in-memory databases which do not play nicely with the default `fork()` behaviour of RQ.
+You may wish to include your RQ tasks inside unit tests. However, many frameworks (such as Django) use in-memory databases, which do not play nicely with the default `fork()` behaviour of RQ.
Therefore, you must use the SimpleWorker class to avoid fork();
@@ -21,6 +21,25 @@ worker.work(burst=True) # Runs enqueued job
```
+## Testing on Windows
+
+If you are testing on a Windows machine you can use the approach above, but with a slight tweak.
+You will need to subclass SimpleWorker to override the default timeout mechanism of the worker.
+Reason: Windows OS does not implement some underlying signals utilized by the default SimpleWorker.
+
+To subclass SimpleWorker for Windows you can do the following:
+
+```python
+from rq import SimpleWorker
+from rq.timeouts import TimerDeathPenalty
+
+class WindowsSimpleWorker(SimpleWorker):
+ death_penalty_class = TimerDeathPenalty
+```
+
+Now you can use WindowsSimpleWorker for running tasks on Windows.
+
+
## Running Jobs in unit tests
Another solution for testing purposes is to use the `is_async=False` queue