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():
4343 "/dictionary" ,
4444)
4545labthing .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+ ),
4749 "/average" ,
4850)
4951
Original file line number Diff line number Diff line change 1+ from labthings .core .tasks import taskify
12from labthings .server .types import (
23 value_to_field ,
34 data_dict_to_schema ,
78 ThingProperty ,
89 PropertySchema ,
910 ThingAction ,
11+ marshal_task ,
1012 use_args ,
1113 Doc ,
1214)
@@ -72,12 +74,19 @@ def _put(self, args):
7274 return generated_class
7375
7476
75- def action_from (function , name : str = None , description = None ):
77+ def action_from (function , name : str = None , description = None , task = False ):
7678
7779 # Create a class name
7880 if not name :
7981 name = f"Action_{ function .__name__ } "
8082
83+ # Create schema
84+ action_schema = function_signature_to_schema (function )
85+
86+ # Handle taskification
87+ if task :
88+ function = taskify (function )
89+
8190 # Create inner functions
8291 def _post (self , args ):
8392 return function (** args )
@@ -86,9 +95,12 @@ def _post(self, args):
8695 generated_class = type (name , (View , object ), {"post" : _post })
8796
8897 # Add decorators for arguments etc
89- action_schema = function_signature_to_schema ( function )
98+
9099 generated_class .post = use_args (action_schema )(generated_class .post )
91100
101+ if task :
102+ generated_class .post = marshal_task (generated_class .post )
103+
92104 generated_class = ThingAction (generated_class )
93105
94106 if description :
You can’t perform that action at this time.
0 commit comments