1
1
<!-- License Badge -->
2
2
[ ![ License] ( https://img.shields.io/badge/License-Apache_2.0-blue.svg )] ( https://github.com/ansible/dispatcher/blob/main/LICENSE )
3
3
4
- Working space for dispatcher prototyping
5
-
6
- This is firstly intended to be a code split of:
4
+ This is intended to be a working space for prototyping a code split of:
7
5
8
6
< https://github.com/ansible/awx/tree/devel/awx/main/dispatch >
9
7
10
8
As a part of doing the split, we also want to resolve a number of
11
9
long-standing design and sustainability issues, thus, asyncio.
12
10
11
+ The philosophy of the dispatcher is to have a limited scope
12
+ as a "local" runner of background tasks, but to be composable
13
+ so that it can be "wrapped" easily to enable clustering and
14
+ distributed task management by apps using it.
15
+
13
16
Licensed under [ Apache Software License 2.0] ( LICENSE )
14
17
15
18
### Usage
@@ -37,20 +40,11 @@ def print_hello():
37
40
print (' hello world!!' )
38
41
```
39
42
40
- #### Dispatcher service
41
-
42
- The dispatcher service needs to be running before you submit tasks.
43
- This does not make any attempts at message durability or confirmation.
44
- If you submit a task in an outage of the service, it will be dropped.
45
-
46
- There are 2 ways to run the dispatcher service:
47
-
48
- - Importing and running (code snippet below)
49
- - A CLI entrypoint ` dispatcher-standalone ` for demo purposes
43
+ Additionally, you need to configure dispatcher somewhere in your import path.
44
+ This tells dispatcher how to submit tasks to be ran.
50
45
51
46
``` python
52
- from dispatcher.main import DispatcherMain
53
- import asyncio
47
+ from dispatcher.config import setup
54
48
55
49
config = {
56
50
" producers" : {
@@ -63,13 +57,29 @@ config = {
63
57
},
64
58
" pool" : {" max_workers" : 4 },
65
59
}
66
- loop = asyncio.get_event_loop()
67
- dispatcher = DispatcherMain(config)
60
+ setup(config)
61
+ ```
62
+
63
+ For more on how to set up and the allowed options in the config,
64
+ see the section [ config] ( docs/config.md ) docs.
65
+
66
+ #### Dispatcher service
67
+
68
+ The dispatcher service needs to be running before you submit tasks.
69
+ This does not make any attempts at message durability or confirmation.
70
+ If you submit a task in an outage of the service, it will be dropped.
71
+
72
+ There are 2 ways to run the dispatcher service:
68
73
69
- try :
70
- loop.run_until_complete(dispatcher.main())
71
- finally :
72
- loop.close()
74
+ - Importing and running (code snippet below)
75
+ - A CLI entrypoint ` dispatcher-standalone ` for demo purposes
76
+
77
+ ``` python
78
+ from dispatcher import run_service
79
+
80
+ # After the setup() method has been called
81
+
82
+ run_service()
73
83
```
74
84
75
85
Configuration tells how to connect to postgres, and what channel(s) to listen to.
@@ -88,6 +98,8 @@ The following code will submit `print_hello` to run in the background dispatcher
88
98
``` python
89
99
from test_methods import print_hello
90
100
101
+ # After the setup() method has been called
102
+
91
103
print_hello.delay()
92
104
```
93
105
@@ -96,6 +108,8 @@ Also valid:
96
108
``` python
97
109
from test_methods import print_hello
98
110
111
+ # After the setup() method has been called
112
+
99
113
print_hello.apply_async(args = [], kwargs = {})
100
114
```
101
115
0 commit comments