File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,9 @@ def cleanup():
43
43
"/dictionary" ,
44
44
)
45
45
labthing .add_view (
46
- action_from (my_component .average_data , description = "Take an averaged measurement" ),
46
+ action_from (
47
+ my_component .average_data , description = "Take an averaged measurement" , task = True
48
+ ),
47
49
"/average" ,
48
50
)
49
51
Original file line number Diff line number Diff line change
1
+ from labthings .core .tasks import taskify
1
2
from labthings .server .types import (
2
3
value_to_field ,
3
4
data_dict_to_schema ,
7
8
ThingProperty ,
8
9
PropertySchema ,
9
10
ThingAction ,
11
+ marshal_task ,
10
12
use_args ,
11
13
Doc ,
12
14
)
@@ -72,12 +74,19 @@ def _put(self, args):
72
74
return generated_class
73
75
74
76
75
- def action_from (function , name : str = None , description = None ):
77
+ def action_from (function , name : str = None , description = None , task = False ):
76
78
77
79
# Create a class name
78
80
if not name :
79
81
name = f"Action_{ function .__name__ } "
80
82
83
+ # Create schema
84
+ action_schema = function_signature_to_schema (function )
85
+
86
+ # Handle taskification
87
+ if task :
88
+ function = taskify (function )
89
+
81
90
# Create inner functions
82
91
def _post (self , args ):
83
92
return function (** args )
@@ -86,9 +95,12 @@ def _post(self, args):
86
95
generated_class = type (name , (View , object ), {"post" : _post })
87
96
88
97
# Add decorators for arguments etc
89
- action_schema = function_signature_to_schema ( function )
98
+
90
99
generated_class .post = use_args (action_schema )(generated_class .post )
91
100
101
+ if task :
102
+ generated_class .post = marshal_task (generated_class .post )
103
+
92
104
generated_class = ThingAction (generated_class )
93
105
94
106
if description :
You can’t perform that action at this time.
0 commit comments