@@ -69,7 +69,10 @@ A :class:`dask_gateway_server.options.Options` object takes two arguments:
69
69
70
70
- ``handler ``: An optional handler function for translating the values set by
71
71
those options into configuration values to set on the corresponding
72
- :ref: `ClusterConfig <cluster-config >`.
72
+ :ref: `ClusterConfig <cluster-config >`. Should have the signature
73
+ ``handler(options) `` or ``handler(options, user) ``, where ``options `` is the
74
+ validated dict of user options, and ``user `` is a ``User `` model for that
75
+ user.
73
76
74
77
``Field `` objects provide typed specifications for a user facing option. There
75
78
are several different ``Field `` classes available, each representing a
@@ -173,7 +176,7 @@ Different Options per User Group
173
176
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
174
177
175
178
Cluster options may be configured to differ based on the user by providing a
176
- function for :data: `c.Backend.cluster_options `. This function recieves a
179
+ function for :data: `c.Backend.cluster_options `. This function receives a
177
180
:class: `dask_gateway_server.models.User ` object and should return a
178
181
:class: `dask_gateway_server.options.Options ` object. It may optionally be an
179
182
``async `` function.
@@ -196,18 +199,46 @@ member of the "power-users" group.
196
199
def generate_options (user ):
197
200
if " power-users" in user.groups:
198
201
options = Options(
199
- Integer(" worker_cores" , default = 1 , min = 1 , max = 4 , label = " Worker Cores" ),
200
- Float(" worker_memory" , default = 1 , min = 1 , max = 8 , label = " Worker Memory (GiB)" ),
202
+ Integer(" worker_cores" , default = 1 , min = 1 , max = 8 , label = " Worker Cores" ),
203
+ Float(" worker_memory" , default = 1 , min = 1 , max = 16 , label = " Worker Memory (GiB)" ),
201
204
handler = options_handler,
202
- )
205
+ )
203
206
else :
204
207
options = Options(
205
- Integer(" worker_cores" , default = 1 , min = 1 , max = 8 , label = " Worker Cores" ),
206
- Float(" worker_memory" , default = 1 , min = 1 , max = 16 , label = " Worker Memory (GiB)" ),
208
+ Integer(" worker_cores" , default = 1 , min = 1 , max = 4 , label = " Worker Cores" ),
209
+ Float(" worker_memory" , default = 1 , min = 1 , max = 8 , label = " Worker Memory (GiB)" ),
207
210
handler = options_handler,
208
- )
211
+ )
209
212
210
213
c.Backend.cluster_options = generate_options
211
214
215
+ User-specific Configuration
216
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
217
+
218
+ Since the ``handler `` function can optionally take in the ``User `` object, you
219
+ can use this to add user-specific configuration. Note that you don't have to
220
+ expose any configuration options to make use of this, the options handler is
221
+ called regardless.
222
+
223
+ Here we configure the worker cores and memory based on the user's groups:
224
+
225
+ .. code-block :: python
226
+
227
+ from dask_gateway_server.options import Options
228
+
229
+ def options_handler (options , user ):
230
+ if " power-users" in user.groups:
231
+ return {
232
+ " worker_cores" : 8 ,
233
+ " worker_memory" : " 16 G"
234
+ }
235
+ else :
236
+ return {
237
+ " worker_cores" : 4 ,
238
+ " worker_memory" : " 8 G"
239
+ }
240
+
241
+ c.Backend.cluster_options = Options(handler = options_handler)
242
+
212
243
213
244
.. _ipywidgets : https://ipywidgets.readthedocs.io/en/latest/
0 commit comments