-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: learn how to start a worker pool
- Loading branch information
Showing
7 changed files
with
85 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,5 @@ tmp | |
|
||
# VS code | ||
.vscode | ||
# Doc | ||
site |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,72 @@ | ||
# Running your app with the `icij-worker` CLI | ||
# Running a worker pool with the [`icij-worker`](https://github.com/ICIJ/icij-python/tree/main/icij-worker) CLI | ||
|
||
In the previous [section](app.md), we've created a simple async app featuring multiple tasks. | ||
|
||
[//]: # (TODO: put ref to the worker pool concept) | ||
We now need start a worker pool, in order to run the app. The workers will execute the app tasks when task execution is requested. | ||
We now need start a [worker pool](./concepts-advanced#worker-pools), in order to run the app. | ||
Workers will execute the app tasks when new tasks are published by the [task manager](./concepts-basic.md#task-manager) through the [broker](./concepts-advanced.md#broker). | ||
|
||
## Installing the `icij-worker` CLI | ||
|
||
## Start a worker pool using the `icij-worker` CLI | ||
Once your app is created you can use your favorite package manager to install [`icij-worker`](https://github.com/ICIJ/icij-python/tree/main/icij-worker): | ||
<!-- termynal --> | ||
``` | ||
$ python -m pip install icij-worker | ||
``` | ||
|
||
|
||
## Start the worker pool | ||
|
||
To start a worker pool we'll need to provide a config. Config can be provided via environment variables or using a config files. | ||
Check out our [worker config guide](../guides/worker-config) in order to learn about all config parameters as well as env var naming conventions. | ||
|
||
### Using environment variables | ||
|
||
Since we've put all of our app code in a variable named `my_app` in a file named `app.py`, we can start the app as following: | ||
<!-- termynal --> | ||
``` | ||
$ ICIJ_WORKER_TYPE=amqp python -m icij-worker workers start -n 2 app.app | ||
[INFO][icij_worker.backend.backend]: Loading worker configuration from env... | ||
[INFO][icij_worker.backend.backend]: worker config: { | ||
... | ||
} | ||
[INFO][icij_worker.backend.mp]: starting 2 worker for app my_app.app | ||
... | ||
``` | ||
!!! note | ||
The above code assumes that an AMQP [broker](./concepts-advanced.md#broker) is running on the default host and ports. | ||
Check out the [broker config guide](../guides/broker-config) to make sure your worker can correctly connect to it. | ||
|
||
Let's break this down a bit | ||
```bash | ||
$ ICIJ_WORKER_TYPE=amqp python -m icij-worker workers start -n 2 app.app | ||
|
||
``` | ||
|
||
### Using a config file | ||
|
||
Sometimes it can be convenient to configure the worker pool via a config file rather than env vars, | ||
in this case you can just drop your config into a file: | ||
|
||
```json title="app_config.json" | ||
{ | ||
"type": "amqp" | ||
} | ||
``` | ||
and start the pool like this: | ||
<!-- termynal --> | ||
``` | ||
$ python -m icij-worker workers start -c app_config.json -n 2 app.app | ||
[INFO][icij_worker.backend.backend]: Loading worker configuration from env... | ||
[INFO][icij_worker.backend.backend]: worker config: { | ||
... | ||
} | ||
[INFO][icij_worker.backend.mp]: starting 2 worker for app my_app.app | ||
... | ||
``` | ||
|
||
## Next | ||
|
||
Here, we've built a basic app and run it using a worker pool. | ||
However, the app we've built is not able yet to speak with Datashare's [Task Manager](concepts-basic.md#task-manager). | ||
|
||
Continue this tutorial to learn how implement task which can be integrated inside Datashare ! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters