|
| 1 | +--- |
| 2 | +description: Overview of the Dispatch CLI. |
| 3 | +--- |
| 4 | + |
| 5 | +# CLI |
| 6 | + |
| 7 | +Dispatch ships with a robust CLI, providing configuration, server, scheduler, plugin, database and shell commands. Here we'll give a partial overview; if you'd like a complete list of Dispatch commands available via the CLI, please use the command `dispatch --help` once you have installed the application. |
| 8 | + |
| 9 | +## Server |
| 10 | + |
| 11 | +The server sub-command contains all Dispatch server related commands. |
| 12 | + |
| 13 | +```bash |
| 14 | +> dispatch server --help develop ⬇ ◼ |
| 15 | +Usage: dispatch server [OPTIONS] COMMAND [ARGS]... |
| 16 | + |
| 17 | + Container for all dispatch server commands. |
| 18 | + |
| 19 | +Options: |
| 20 | + --help Show this message and exit. |
| 21 | + |
| 22 | +Commands: |
| 23 | + config Prints the current config as dispatch sees it. |
| 24 | + develop Runs a simple server for development. |
| 25 | + routes Prints all available routes. |
| 26 | + shell Starts an ipython shell importing our app. |
| 27 | + start |
| 28 | +``` |
| 29 | + |
| 30 | +### Config |
| 31 | + |
| 32 | +The `config` command is helpful in debugging as it shows the configuration variables as they are seen by the server \(combining envvars, defaults and the .env file\). |
| 33 | + |
| 34 | +```bash |
| 35 | +> dispatch server config |
| 36 | +> |
| 37 | +Key Value |
| 38 | +---------------------------------------- ----------------------- |
| 39 | +DISPATCH_DOMAIN example.com |
| 40 | +STATIC_DIR |
| 41 | +METRIC_PROVIDERS spectator-metric |
| 42 | +... |
| 43 | +``` |
| 44 | + |
| 45 | +### Develop |
| 46 | + |
| 47 | +The `develop` command is used to start a development server. This server will continually watch for file changes and reload the server accordingly. You'll find it useful to combine this with a `DEBUG` log level, as below. |
| 48 | + |
| 49 | +```bash |
| 50 | +> dispatch server develop --log-level debug |
| 51 | +``` |
| 52 | + |
| 53 | +### Routes |
| 54 | + |
| 55 | +The `routes` command is useful for development. It shows a not only which endpoints at which the server is currently listening, but also the HTTP verb methods that are accepted, and whether or not authentication is enabled for the endpoint. |
| 56 | + |
| 57 | +```bash |
| 58 | +> dispatch server routes |
| 59 | +Path Authenticated Methods |
| 60 | +------------------------------------ --------------- --------- |
| 61 | +/healthcheck False GET |
| 62 | +/documents/ True GET |
| 63 | +/documents/{document_id} True GET |
| 64 | +/documents/ True POST |
| 65 | +... |
| 66 | +``` |
| 67 | + |
| 68 | +### Shell |
| 69 | + |
| 70 | +The `shell` command is useful for development. It drops you into a python interactive shell with the same context as the server itself. |
| 71 | + |
| 72 | +```bash |
| 73 | +> dispatch server shell |
| 74 | +``` |
| 75 | + |
| 76 | +### Start |
| 77 | + |
| 78 | +The `start` command is used to start a production grade Dispatch web server. It's really an alias to the [uvicorn](https://www.uvicorn.org/) webserver, so it contains all of the options and flags available with that server. |
| 79 | + |
| 80 | +```bash |
| 81 | +> dispatch server start --help |
| 82 | +Usage: dispatch server start [OPTIONS] APP |
| 83 | + |
| 84 | +Options: |
| 85 | + --host TEXT Bind socket to this host. [default: |
| 86 | + 127.0.0.1] |
| 87 | + --port INTEGER Bind socket to this port. [default: 8000] |
| 88 | + --uds TEXT Bind to a UNIX domain socket. |
| 89 | + --fd INTEGER Bind to socket from this file descriptor. |
| 90 | + --reload Enable auto-reload. |
| 91 | + --reload-dir TEXT Set reload directories explicitly, instead |
| 92 | + of using the current working directory. |
| 93 | + ... |
| 94 | +``` |
| 95 | + |
| 96 | +To start Dispatch you will need to tell the start command where to find the `dispatch` [ASGI](https://asgi.readthedocs.io/en/latest/) application. For example a common set of flags might be: |
| 97 | + |
| 98 | +```bash |
| 99 | +> dispatch server start dispatch.main:app --workers 6 --host 127.0.0.1 --port 8000 --proxy-headers |
| 100 | +``` |
| 101 | + |
| 102 | +## Scheduler |
| 103 | + |
| 104 | +The `scheduler` command contains all of the Dispatch scheduler logic. |
| 105 | + |
| 106 | +```bash |
| 107 | +> dispatch scheduler --help |
| 108 | +Usage: dispatch scheduler [OPTIONS] COMMAND [ARGS]... |
| 109 | + |
| 110 | + Container for all dispatch scheduler commands. |
| 111 | + |
| 112 | +Options: |
| 113 | + --help Show this message and exit. |
| 114 | + |
| 115 | +Commands: |
| 116 | + list Prints and runs all currently configured periodic tasks, in... |
| 117 | + start Starts the scheduler. |
| 118 | +``` |
| 119 | + |
| 120 | +### List |
| 121 | + |
| 122 | +The `list` command lists all tasks that are currently registered with the scheduler. Today the scheduler periods are hard coded and cannot be adjusted. |
| 123 | + |
| 124 | +```bash |
| 125 | +> dispatch scheduler list |
| 126 | +Task Name Period At Time |
| 127 | +------------------------------- -------------- --------- |
| 128 | +incident-status-report-reminder 1:00:00 |
| 129 | +incident-daily-summary 1 day, 0:00:00 18:00:00 |
| 130 | +calculate-incident-cost 0:05:00 |
| 131 | +incident-task-reminders 1:00:00 |
| 132 | +incident-task-sync 0:00:30 |
| 133 | +term-sync 1:00:00 |
| 134 | +document-term-sync 1 day, 0:00:00 |
| 135 | +application-sync 1:00:00 |
| 136 | +``` |
| 137 | + |
| 138 | +### Start |
| 139 | + |
| 140 | +The `start` command starts the scheduler, and allows tasks be executed based on the defined period. |
| 141 | + |
| 142 | +```bash |
| 143 | +> dispatch scheduler start |
| 144 | +Starting scheduler... |
| 145 | +``` |
| 146 | + |
| 147 | +Often it's helpful to run a particular task immediately: |
| 148 | + |
| 149 | +```bash |
| 150 | +> dispatch scheduler start incident-status-report-reminder --eager |
| 151 | +``` |
| 152 | + |
| 153 | +## Database |
| 154 | + |
| 155 | +The `database` command contains all of the Dispatch database logic. |
| 156 | + |
| 157 | +```bash |
| 158 | +> dispatch database --help |
| 159 | +Usage: dispatch database [OPTIONS] COMMAND [ARGS]... |
| 160 | + |
| 161 | + Container for all dispatch database commands. |
| 162 | + |
| 163 | +Options: |
| 164 | + --help Show this message and exit. |
| 165 | + |
| 166 | +Commands: |
| 167 | + downgrade Downgrades database schema to next newest version. |
| 168 | + drop Drops all data in database. |
| 169 | + heads Shows the heads of the database. |
| 170 | + history Shows the history of the database. |
| 171 | + init Initializes a new database. |
| 172 | + populate Populates database with default values. |
| 173 | + revision Create new database revision. |
| 174 | + sync-triggers Ensures that all database triggers have been installed. |
| 175 | + upgrade Upgrades database schema to newest version. |
| 176 | +``` |
| 177 | + |
| 178 | +{% hint style="info" %} |
| 179 | +Note: The database command is a combination of custom commands and `alembic` commands. For more information about alembic database migrations see [here](https://alembic.sqlalchemy.org/en/latest/). |
| 180 | +{% endhint %} |
| 181 | + |
| 182 | +### Init |
| 183 | + |
| 184 | +The `init` command takes a fresh database and creates the necessary tables and values for Dispatch to operate. |
| 185 | + |
| 186 | +```bash |
| 187 | +> dispatch database init |
| 188 | +``` |
| 189 | + |
| 190 | +### Revision |
| 191 | + |
| 192 | +The `revision` command is an `alembic` command that creates a new database schema revision based on the models defined within the application. |
| 193 | + |
| 194 | +It's most often used with the `--autogenerate` flag: |
| 195 | + |
| 196 | +```bash |
| 197 | +> dispatch database revision --autoge |
| 198 | +``` |
| 199 | + |
| 200 | +### Upgrade/Downgrade |
| 201 | + |
| 202 | +The `upgrade` and `downgrade` commands manage how `alembic` database migrations are deployed, allowing you to move the database forward and backward through revisions. You'll often need to run the `upgrade` command after installing a new version of Dispatch. |
| 203 | + |
| 204 | +```bash |
| 205 | +> dispatch database upgrade |
| 206 | +``` |
| 207 | + |
| 208 | +## Plugins |
| 209 | + |
| 210 | +The `plugin` command contains all of the logic for dealing with Dispatch's plugins. |
| 211 | + |
| 212 | +### List |
| 213 | + |
| 214 | +The `list` command lists all currently available plugins. This is useful in determining which plugins are available to be used via configuration variables. |
| 215 | + |
| 216 | +```bash |
| 217 | +> dispatch database list |
| 218 | +Title Slug Version Type Author Description |
| 219 | +-------------------------------- ------------------------------ ---------- ----------------- ------------- --------------------------------------------------------- |
| 220 | +Dispatch - Document Resolver dispatch-document-resolver 0.1.0 document-resolver Kevin Glisson Uses dispatch itself to resolve incident documents. |
| 221 | +Dispatch - Participants dispatch-participants 0.1.0 participant Kevin Glisson Uses dispatch itself to determine participants. |
| 222 | +Google Docs - Document google-docs-document 0.1.0 document Kevin Glisson Uses google docs to manage document contents. |
| 223 | +Google Gmail - Conversation google-gmail-conversation 0.1.0 conversation Kevin Glisson Uses gmail to facilitate conversations. |
| 224 | +Google Group - Participant Group google-group-participant-group 0.1.0 participant_group Kevin Glisson Uses Google Groups to help manage participant membership. |
| 225 | +... |
| 226 | +``` |
| 227 | + |
| 228 | + |
| 229 | + |
0 commit comments