mirror of
https://github.com/inventree/InvenTree.git
synced 2026-04-12 14:28:55 +00:00
Worker debugging (#11677)
* Add debugging info for background workers to the devcontainer docs * Add debugging info the the EventMixin docs * Add an option to set sync=True to launch.json
This commit is contained in:
4
.vscode/launch.json
vendored
4
.vscode/launch.json
vendored
@@ -36,7 +36,9 @@
|
||||
"program": "${workspaceFolder}/src/backend/InvenTree/manage.py",
|
||||
"args": [
|
||||
"runserver",
|
||||
"0.0.0.0:8000"
|
||||
"0.0.0.0:8000",
|
||||
// "--sync",// Synchronize worker tasks to foreground thread
|
||||
// "--noreload", // disable auto-reload
|
||||
],
|
||||
"django": true,
|
||||
"justMyCode": false
|
||||
|
||||
@@ -60,7 +60,12 @@ If you only need a superuser, run the `superuser` task. It should prompt you for
|
||||
|
||||
#### Run background workers
|
||||
|
||||
If you need to process your queue with background workers, run the `worker` task. This is a foreground task which will execute in the terminal.
|
||||
If you need to process your queue with background workers, open a new terminal and run the `worker` task with `invoke worker`. This is a foreground task which will execute in the terminal.
|
||||
|
||||
If you are developing functions that will be executed by background workers there are a two debugging options.
|
||||
|
||||
- If the workers are started with the `worker` task you can add `print` or `logger` statements to the code and monitor the output in the terminal.
|
||||
- All tasks can be forced to run in the foreground worker by uncommenting the `--sync` and `--noreload` arguments under the `InvenTree Server - 3rd party` entry in `.vscode/launch.json`. With this setting you should not start a separate background worker, instead you start the `InvenTree Server - 3rd party` from the `Run and Debug` side panel. All task will now run in one single process and you can set breakpoints, inspect variables and single step also tasks that normally are offloaded to background workers. It should be noted that with this setting the GUI will be unresponsive while tasks are executed.
|
||||
|
||||
### Running InvenTree
|
||||
|
||||
|
||||
@@ -13,6 +13,9 @@ When a certain (server-side) event occurs, the background worker passes the even
|
||||
|
||||
{{ image("plugin/enable_events.png", "Enable event integration") }}
|
||||
|
||||
!!! info "Worker debugging"
|
||||
As the events are offloaded to a background worker debugging the `process_event()` function need some extra consideration. Please see the [Run background workers](../../develop/devcontainer.md#run-background-workers) section for further information.
|
||||
|
||||
## Events
|
||||
|
||||
Events are passed through using a string identifier, e.g. `build.completed`
|
||||
|
||||
@@ -865,6 +865,16 @@ BACKGROUND_WORKER_ATTEMPTS = int(
|
||||
get_setting('INVENTREE_BACKGROUND_MAX_ATTEMPTS', 'background.max_attempts', 5)
|
||||
)
|
||||
|
||||
# Check if '--sync' was passed in the command line
|
||||
if '--sync' in sys.argv and '--noreload' in sys.argv and DEBUG:
|
||||
SYNC_TASKS = True
|
||||
else:
|
||||
SYNC_TASKS = False
|
||||
|
||||
# Clean up sys.argv so Django doesn't complain about an unknown argument
|
||||
if SYNC_TASKS:
|
||||
sys.argv.remove('--sync')
|
||||
|
||||
# django-q background worker configuration
|
||||
Q_CLUSTER = {
|
||||
'name': 'InvenTree',
|
||||
@@ -879,7 +889,7 @@ Q_CLUSTER = {
|
||||
'bulk': 10,
|
||||
'orm': 'default',
|
||||
'cache': 'default',
|
||||
'sync': False,
|
||||
'sync': SYNC_TASKS,
|
||||
'poll': 1.5,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user