@@ -53,6 +53,14 @@ pub fn routes(
53
53
. and ( auth_filter ( data. clone ( ) , TokenType :: Agent ) )
54
54
. map ( endpoint_heartbeat) ;
55
55
56
+ let error = warp:: post2 ( )
57
+ . and ( warp:: path ( "error" ) )
58
+ . and ( warp:: path:: end ( ) )
59
+ . and ( warp:: body:: json ( ) )
60
+ . and ( data_filter. clone ( ) )
61
+ . and ( auth_filter ( data. clone ( ) , TokenType :: Agent ) )
62
+ . map ( endpoint_error) ;
63
+
56
64
warp:: any ( )
57
65
. and (
58
66
config
@@ -63,6 +71,8 @@ pub fn routes(
63
71
. or ( record_progress)
64
72
. unify ( )
65
73
. or ( heartbeat)
74
+ . unify ( )
75
+ . or ( error)
66
76
. unify ( ) ,
67
77
)
68
78
. map ( handle_results)
@@ -146,6 +156,25 @@ fn endpoint_heartbeat(data: Arc<Data>, auth: AuthDetails) -> Fallible<Response<B
146
156
Ok ( ApiResponse :: Success { result : true } . into_response ( ) ?)
147
157
}
148
158
159
+ fn endpoint_error ( error : String , data : Arc < Data > , auth : AuthDetails ) -> Fallible < Response < Body > > {
160
+ let ex = Experiment :: run_by ( & data. db , & Assignee :: Agent ( auth. name . clone ( ) ) ) ?
161
+ . ok_or_else ( || err_msg ( "no experiment run by this agent" ) ) ?;
162
+
163
+ if let Some ( ref github_issue) = ex. github_issue {
164
+ Message :: new ( )
165
+ . line (
166
+ "exclamation" ,
167
+ format ! (
168
+ "Experiment **`{}`** **running** on agent `{}` has encountered an error" ,
169
+ ex. name, auth. name,
170
+ ) ,
171
+ )
172
+ . line ( "" , format ! ( "error: {}" , error, ) )
173
+ . send ( & github_issue. api_url , & data) ?;
174
+ }
175
+ Ok ( ApiResponse :: Success { result : true } . into_response ( ) ?)
176
+ }
177
+
149
178
fn handle_results ( resp : Fallible < Response < Body > > ) -> Response < Body > {
150
179
match resp {
151
180
Ok ( resp) => resp,
0 commit comments