Skip to content
Merged
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
4 changes: 3 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion docs/docs/develop/devcontainer.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions docs/docs/plugins/mixins/event.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
12 changes: 11 additions & 1 deletion src/backend/InvenTree/InvenTree/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,16 @@
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',
Expand All @@ -874,7 +884,7 @@
'bulk': 10,
'orm': 'default',
'cache': 'default',
'sync': False,
'sync': SYNC_TASKS,
'poll': 1.5,
}

Expand Down
Loading