@@ -30,7 +30,7 @@ type t = API.ref_task
30
30
(* creates a new task *)
31
31
let make ~__context ~http_other_config ?(description = " " ) ?session_id
32
32
?subtask_of label : t * t Uuidx.t =
33
- Context. with_tracing ~__context __FUNCTION__ @@ fun __context ->
33
+ let @ __context = Context. with_tracing ~__context __FUNCTION__ in
34
34
let uuid = Uuidx. make () in
35
35
let uuid_str = Uuidx. to_string uuid in
36
36
let ref = Ref. make () in
@@ -61,7 +61,7 @@ let rbac_assert_permission_fn = ref None
61
61
(* required to break dep-cycle with rbac.ml *)
62
62
63
63
let assert_op_valid ?(ok_if_no_session_in_context = false ) ~__context task_id =
64
- Context. with_tracing ~__context __FUNCTION__ @@ fun __context ->
64
+ let @ __context = Context. with_tracing ~__context __FUNCTION__ in
65
65
let assert_permission_task_op_any () =
66
66
match ! rbac_assert_permission_fn with
67
67
| None ->
@@ -109,15 +109,15 @@ let assert_op_valid ?(ok_if_no_session_in_context = false) ~__context task_id =
109
109
assert_permission_task_op_any ()
110
110
111
111
let get_name ~__context =
112
- Context. with_tracing ~__context __FUNCTION__ @@ fun __context ->
112
+ let @ __context = Context. with_tracing ~__context __FUNCTION__ in
113
113
let task_id = Context. get_task_id __context in
114
114
if Ref. is_dummy task_id then
115
115
Ref. name_of_dummy task_id
116
116
else
117
117
Db.Task. get_name_label ~__context ~self: task_id
118
118
119
119
let destroy ~__context task_id =
120
- Context. with_tracing ~__context __FUNCTION__ @@ fun __context ->
120
+ let @ __context = Context. with_tracing ~__context __FUNCTION__ in
121
121
if not (Ref. is_dummy task_id) then (
122
122
assert_op_valid ~ok_if_no_session_in_context: true ~__context task_id ;
123
123
Db_actions.DB_Action.Task. destroy ~__context ~self: task_id
@@ -133,40 +133,36 @@ let init () =
133
133
Context. __make_task := make
134
134
135
135
let operate_on_db_task ~__context f =
136
- Context. with_tracing ~__context __FUNCTION__ @@ fun __context ->
136
+ let @ __context = Context. with_tracing ~__context __FUNCTION__ in
137
137
if Context. task_in_database __context then
138
138
f (Context. get_task_id __context)
139
139
140
140
let set_description ~__context value =
141
- Context. with_tracing ~__context __FUNCTION__ @@ fun __context ->
142
- operate_on_db_task ~__context (fun self ->
143
- Db_actions.DB_Action.Task. set_name_description ~__context ~self ~value
144
- )
141
+ let @ __context = Context. with_tracing ~__context __FUNCTION__ in
142
+ let @ self = operate_on_db_task ~__context in
143
+ Db_actions.DB_Action.Task. set_name_description ~__context ~self ~value
145
144
146
145
let add_to_other_config ~__context key value =
147
- Context. with_tracing ~__context __FUNCTION__ @@ fun __context ->
148
- operate_on_db_task ~__context (fun self ->
149
- Db_actions.DB_Action.Task. remove_from_other_config ~__context ~self ~key ;
150
- Db_actions.DB_Action.Task. add_to_other_config ~__context ~self ~key ~value
151
- )
146
+ let @ __context = Context. with_tracing ~__context __FUNCTION__ in
147
+ let @ self = operate_on_db_task ~__context in
148
+ Db_actions.DB_Action.Task. remove_from_other_config ~__context ~self ~key ;
149
+ Db_actions.DB_Action.Task. add_to_other_config ~__context ~self ~key ~value
152
150
153
151
let set_progress ~__context value =
154
- Context. with_tracing ~__context __FUNCTION__ @@ fun __context ->
155
- operate_on_db_task ~__context (fun self ->
156
- Db_actions.DB_Action.Task. set_progress ~__context ~self ~value
157
- )
152
+ let @ __context = Context. with_tracing ~__context __FUNCTION__ in
153
+ let @ self = operate_on_db_task ~__context in
154
+ Db_actions.DB_Action.Task. set_progress ~__context ~self ~value
158
155
159
156
let set_external_pid ~__context pid =
160
- Context. with_tracing ~__context __FUNCTION__ @@ fun __context ->
161
- operate_on_db_task ~__context (fun self ->
162
- Db_actions.DB_Action.Task. set_externalpid ~__context ~self
163
- ~value: (Int64. of_int pid)
164
- )
157
+ let @ __context = Context. with_tracing ~__context __FUNCTION__ in
158
+ let @ self = operate_on_db_task ~__context in
159
+ Db_actions.DB_Action.Task. set_externalpid ~__context ~self
160
+ ~value: (Int64. of_int pid)
165
161
166
162
let clear_external_pid ~__context = set_external_pid ~__context (- 1 )
167
163
168
164
let set_result_on_task ~__context task_id result =
169
- Context. with_tracing ~__context __FUNCTION__ @@ fun __context ->
165
+ let @ __context = Context. with_tracing ~__context __FUNCTION__ in
170
166
match result with
171
167
| None ->
172
168
()
@@ -176,8 +172,9 @@ let set_result_on_task ~__context task_id result =
176
172
177
173
(* * Only set the result without completing the task. Useful for vm import *)
178
174
let set_result ~__context result =
179
- Context. with_tracing ~__context __FUNCTION__ @@ fun __context ->
180
- operate_on_db_task ~__context (fun t -> set_result_on_task ~__context t result)
175
+ let @ __context = Context. with_tracing ~__context __FUNCTION__ in
176
+ let @ self = operate_on_db_task ~__context in
177
+ set_result_on_task ~__context self result
181
178
182
179
let status_to_string = function
183
180
| `pending ->
@@ -196,38 +193,35 @@ let status_is_completed task_status =
196
193
197
194
let complete ~__context result =
198
195
let @ () = finally_complete_tracing __context in
199
- operate_on_db_task ~__context ( fun self ->
200
- let status = Db_actions.DB_Action.Task. get_status ~__context ~self in
201
- if status = `pending then (
202
- Db_actions.DB_Action.Task. set_allowed_operations ~__context ~self
203
- ~value: [] ;
204
- Db_actions.DB_Action.Task. set_finished ~__context ~self
205
- ~value: ( Date. now () ) ;
206
- Db_actions.DB_Action.Task. set_progress ~__context ~self ~ value:1. ;
207
- set_result_on_task ~__context self result ;
208
- Db_actions.DB_Action.Task. set_status ~__context ~ self ~value: `success
209
- ) else
210
- debug " the status of %s is: %s; cannot set it to `success "
211
- ( Ref. really_pretty_and_small self)
212
- (status_to_string status )
213
- )
196
+ let @ self = operate_on_db_task ~__context in
197
+ let status = Db_actions.DB_Action.Task. get_status ~__context ~self in
198
+ match status with
199
+ | `pending ->
200
+ Db_actions.DB_Action.Task. set_allowed_operations ~__context ~self
201
+ ~value: [] ;
202
+ Db_actions.DB_Action.Task. set_finished ~__context ~self
203
+ ~ value:( Date. now () ) ;
204
+ Db_actions.DB_Action.Task. set_progress ~__context ~ self ~value: 1. ;
205
+ set_result_on_task ~__context self result ;
206
+ Db_actions.DB_Action.Task. set_status ~__context ~self ~value: `success
207
+ | _ ->
208
+ debug " the status of %s is: %s; cannot set it to `success "
209
+ ( Ref. really_pretty_and_small self )
210
+ (status_to_string status )
214
211
215
212
let set_cancellable ~__context =
216
- Context. with_tracing ~__context __FUNCTION__ @@ fun __context ->
217
- operate_on_db_task ~__context (fun self ->
218
- Db_actions.DB_Action.Task. set_allowed_operations ~__context ~self
219
- ~value: [`cancel ]
220
- )
213
+ let @ __context = Context. with_tracing ~__context __FUNCTION__ in
214
+ let @ self = operate_on_db_task ~__context in
215
+ Db_actions.DB_Action.Task. set_allowed_operations ~__context ~self
216
+ ~value: [`cancel ]
221
217
222
218
let set_not_cancellable ~__context =
223
- Context. with_tracing ~__context __FUNCTION__ @@ fun __context ->
224
- operate_on_db_task ~__context (fun self ->
225
- Db_actions.DB_Action.Task. set_allowed_operations ~__context ~self
226
- ~value: []
227
- )
219
+ let @ __context = Context. with_tracing ~__context __FUNCTION__ in
220
+ let @ self = operate_on_db_task ~__context in
221
+ Db_actions.DB_Action.Task. set_allowed_operations ~__context ~self ~value: []
228
222
229
223
let is_cancelling ~__context =
230
- Context. with_tracing ~__context __FUNCTION__ @@ fun __context ->
224
+ let @ __context = Context. with_tracing ~__context __FUNCTION__ in
231
225
Context. task_in_database __context
232
226
&&
233
227
let l =
@@ -237,12 +231,12 @@ let is_cancelling ~__context =
237
231
List. exists (fun (_ , x ) -> x = `cancel ) l
238
232
239
233
let raise_cancelled ~__context =
240
- Context. with_tracing ~__context __FUNCTION__ @@ fun __context ->
234
+ let @ __context = Context. with_tracing ~__context __FUNCTION__ in
241
235
let task_id = Context. get_task_id __context in
242
236
raise Api_errors. (Server_error (task_cancelled, [Ref. string_of task_id]))
243
237
244
238
let exn_if_cancelling ~__context =
245
- Context. with_tracing ~__context __FUNCTION__ @@ fun __context ->
239
+ let @ __context = Context. with_tracing ~__context __FUNCTION__ in
246
240
if is_cancelling ~__context then
247
241
raise_cancelled ~__context
248
242
@@ -261,40 +255,40 @@ let cancel_this ~__context ~self =
261
255
(status_to_string status)
262
256
263
257
let cancel ~__context =
264
- Context. with_tracing ~__context __FUNCTION__ @@ fun __context ->
265
- operate_on_db_task ~__context (fun self -> cancel_this ~__context ~self )
258
+ let @ __context = Context. with_tracing ~__context __FUNCTION__ in
259
+ let @ self = operate_on_db_task ~__context in
260
+ cancel_this ~__context ~self
266
261
267
262
let failed ~__context exn =
268
263
let backtrace = Printexc. get_backtrace () in
269
264
let @ () = finally_complete_tracing ~error: (exn , backtrace) __context in
270
265
let code, params = ExnHelper. error_of_exn exn in
271
- operate_on_db_task ~__context (fun self ->
272
- let status = Db_actions.DB_Action.Task. get_status ~__context ~self in
273
- if status = `pending then (
274
- Db_actions.DB_Action.Task. set_progress ~__context ~self ~value: 1. ;
275
- Db_actions.DB_Action.Task. set_error_info ~__context ~self
276
- ~value: (code :: params) ;
277
- Db_actions.DB_Action.Task. set_backtrace ~__context ~self
278
- ~value: (Sexplib.Sexp. to_string Backtrace. (sexp_of_t (get exn ))) ;
279
- Db_actions.DB_Action.Task. set_finished ~__context ~self
280
- ~value: (Date. now () ) ;
281
- Db_actions.DB_Action.Task. set_allowed_operations ~__context ~self
282
- ~value: [] ;
283
- if code = Api_errors. task_cancelled then
284
- Db_actions.DB_Action.Task. set_status ~__context ~self
285
- ~value: `cancelled
286
- else
287
- Db_actions.DB_Action.Task. set_status ~__context ~self ~value: `failure
288
- ) else
289
- debug " the status of %s is %s; cannot set it to %s"
290
- (Ref. really_pretty_and_small self)
291
- (status_to_string status)
292
- ( if code = Api_errors. task_cancelled then
293
- " `cancelled"
294
- else
295
- " `failure"
296
- )
297
- )
266
+ let @ self = operate_on_db_task ~__context in
267
+ let status = Db_actions.DB_Action.Task. get_status ~__context ~self in
268
+ match status with
269
+ | `pending ->
270
+ Db_actions.DB_Action.Task. set_progress ~__context ~self ~value: 1. ;
271
+ Db_actions.DB_Action.Task. set_error_info ~__context ~self
272
+ ~value: (code :: params) ;
273
+ Db_actions.DB_Action.Task. set_backtrace ~__context ~self
274
+ ~value: (Sexplib.Sexp. to_string Backtrace. (sexp_of_t (get exn ))) ;
275
+ Db_actions.DB_Action.Task. set_finished ~__context ~self
276
+ ~value: (Date. now () ) ;
277
+ Db_actions.DB_Action.Task. set_allowed_operations ~__context ~self
278
+ ~value: [] ;
279
+ if code = Api_errors. task_cancelled then
280
+ Db_actions.DB_Action.Task. set_status ~__context ~self ~value: `cancelled
281
+ else
282
+ Db_actions.DB_Action.Task. set_status ~__context ~self ~value: `failure
283
+ | _ ->
284
+ debug " the status of %s is %s; cannot set it to %s"
285
+ (Ref. really_pretty_and_small self)
286
+ (status_to_string status)
287
+ ( if code = Api_errors. task_cancelled then
288
+ " `cancelled"
289
+ else
290
+ " `failure"
291
+ )
298
292
299
293
type id = Sm of string | Xenops of string * string
300
294
@@ -313,7 +307,7 @@ let task_to_id_exn task =
313
307
with_lock task_tbl_m (fun () -> Hashtbl. find task_to_id_tbl task)
314
308
315
309
let register_task __context ?(cancellable = true ) id =
316
- Context. with_tracing ~__context __FUNCTION__ @@ fun __context ->
310
+ let @ __context = Context. with_tracing ~__context __FUNCTION__ in
317
311
let task = Context. get_task_id __context in
318
312
with_lock task_tbl_m (fun () ->
319
313
Hashtbl. replace id_to_task_tbl id task ;
@@ -329,7 +323,7 @@ let register_task __context ?(cancellable = true) id =
329
323
()
330
324
331
325
let unregister_task __context id =
332
- Context. with_tracing ~__context __FUNCTION__ @@ fun __context ->
326
+ let @ __context = Context. with_tracing ~__context __FUNCTION__ in
333
327
(* The rest of the XenAPI Task won't be cancellable *)
334
328
set_not_cancellable ~__context ;
335
329
with_lock task_tbl_m (fun () ->
0 commit comments