@@ -53,6 +53,14 @@ pub fn routes(
5353 . and ( auth_filter ( data. clone ( ) , TokenType :: Agent ) )
5454 . map ( endpoint_heartbeat) ;
5555
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+
5664 warp:: any ( )
5765 . and (
5866 config
@@ -63,6 +71,8 @@ pub fn routes(
6371 . or ( record_progress)
6472 . unify ( )
6573 . or ( heartbeat)
74+ . unify ( )
75+ . or ( error)
6676 . unify ( ) ,
6777 )
6878 . map ( handle_results)
@@ -146,6 +156,25 @@ fn endpoint_heartbeat(data: Arc<Data>, auth: AuthDetails) -> Fallible<Response<B
146156 Ok ( ApiResponse :: Success { result : true } . into_response ( ) ?)
147157}
148158
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+
149178fn handle_results ( resp : Fallible < Response < Body > > ) -> Response < Body > {
150179 match resp {
151180 Ok ( resp) => resp,
0 commit comments