@@ -100,85 +100,114 @@ private async Task StartLogPolling(CancellationToken cancellationToken)
100100
101101 private Result < JObject > RunTask ( string name , JObject input , JObject runConfig )
102102 {
103- var output = RunRivetCLI ( "task" , "run" , "--run-config" , runConfig . ToString ( Formatting . None ) , "--name" , name , "--input" , input . ToString ( Formatting . None ) ) ;
104- switch ( output )
105- {
106- case ResultOk < JObject > ok :
107- if ( ok . Data . GetValue ( "Ok" ) ? . Value < JObject > ( ) is { } okInner )
108- {
109- RivetLogger . Log ( $ "Task { name } Success: { okInner . ToString ( Formatting . None ) } ") ;
110- return new ResultOk < JObject > ( okInner ) ;
111- }
112- else if ( ok . Data . GetValue ( "Err" ) is { } errInner )
113- {
114- RivetLogger . Log ( $ "Task { name } Err: { errInner } ") ;
115- return new ResultErr < JObject > ( errInner . ToString ( Formatting . None ) ) ;
116- }
117- else
118- {
119- throw new Exception ( "unreachable" ) ;
120- }
121- case ResultErr < JObject > err :
122- RivetLogger . Log ( $ "Task { name } Command Err: { err . Message } ") ;
123- return err ;
124- default :
125- throw new Exception ( "unreachable" ) ;
126- }
127- }
128-
129- public static string GetRivetCLIPath ( )
130- {
131- // TODO: Update this path as needed
132- return "/Users/nathan/rivet/cli/target/debug/rivet-cli" ;
133- }
134-
135- private static Result < JObject > RunRivetCLI ( params string [ ] args )
136- {
137- // TODO: Turn this on if debug is enabled
138- RivetLogger . Log ( $ "Running Rivet CLI: { GetRivetCLIPath ( ) } { string . Join ( " " , args ) } ") ;
139-
140- if ( ! File . Exists ( GetRivetCLIPath ( ) ) )
141- {
142- return new ResultErr < JObject > ( "File does not exist: " + GetRivetCLIPath ( ) ) ;
143- }
144-
145- var startInfo = new ProcessStartInfo
146- {
147- FileName = GetRivetCLIPath ( ) ,
148- RedirectStandardOutput = true ,
149- RedirectStandardError = true ,
150- UseShellExecute = false ,
151- CreateNoWindow = true ,
152- } ;
153- foreach ( var arg in args ) {
154- startInfo . ArgumentList . Add ( arg ) ;
155- }
156-
157103 try
158104 {
159- using var process = Process . Start ( startInfo ) ;
160- var stdout = process . StandardOutput . ReadToEnd ( ) ;
161- var stderr = process . StandardError . ReadToEnd ( ) ;
162- process . WaitForExit ( ) ;
163-
164- RivetLogger . Log ( $ "Process output:\n \n { stdout } \n \n { stderr } ") ;
165-
166- if ( process . ExitCode == 0 )
105+ var outputRaw = RivetToolchain . RunTaskRaw ( runConfig . ToString ( Formatting . None ) , name , input . ToString ( Formatting . None ) ) ;
106+ var output = JObject . Parse ( outputRaw ) ;
107+ if ( output . GetValue ( "Ok" ) ? . Value < JObject > ( ) is { } okInner )
167108 {
168- return new ResultOk < JObject > ( JObject . Parse ( stdout ) ) ;
109+ RivetLogger . Log ( $ "Task { name } Success: { okInner . ToString ( Formatting . None ) } ") ;
110+ return new ResultOk < JObject > ( okInner ) ;
111+ }
112+ else if ( output . GetValue ( "Err" ) is { } errInner )
113+ {
114+ RivetLogger . Log ( $ "Task { name } Err: { errInner } ") ;
115+ return new ResultErr < JObject > ( errInner . ToString ( Formatting . None ) ) ;
169116 }
170117 else
171118 {
172- return new ResultErr < JObject > ( $ "Process failed with exit code { process . ExitCode } \n \n stdout: \n { stdout } \n \n stderr: \n { stderr } ") ;
119+ throw new Exception ( "unreachable ") ;
173120 }
174121 }
175- catch ( System . Exception ex )
122+ catch ( Exception error )
176123 {
177- return new ResultErr < JObject > ( "Failed to start process: " + ex . Message ) ;
124+ UnityEngine . Debug . LogError ( $ "Error running task: { error } ") ;
125+ return new ResultErr < JObject > ( error . ToString ( ) ) ;
178126 }
127+ }
179128
129+ // private Result<JObject> RunTask(string name, JObject input, JObject runConfig)
130+ // {
131+ // var output = RunRivetCLI("task", "run", "--run-config", runConfig.ToString(Formatting.None), "--name", name, "--input", input.ToString(Formatting.None));
132+ // switch (output)
133+ // {
134+ // case ResultOk<JObject> ok:
135+ // if (ok.Data.GetValue("Ok")?.Value<JObject>() is { } okInner)
136+ // {
137+ // RivetLogger.Log($"Task {name} Success: {okInner.ToString(Formatting.None)}");
138+ // return new ResultOk<JObject>(okInner);
139+ // }
140+ // else if (ok.Data.GetValue("Err") is { } errInner)
141+ // {
142+ // RivetLogger.Log($"Task {name} Err: {errInner}");
143+ // return new ResultErr<JObject>(errInner.ToString(Formatting.None));
144+ // }
145+ // else
146+ // {
147+ // throw new Exception("unreachable");
148+ // }
149+ // case ResultErr<JObject> err:
150+ // RivetLogger.Log($"Task {name} Command Err: {err.Message}");
151+ // return err;
152+ // default:
153+ // throw new Exception("unreachable");
154+ // }
155+ // }
156+
157+ // TODO: Remove this
158+ public static string GetRivetCLIPath ( )
159+ {
160+ // TODO: Update this path as needed
161+ return "/Users/nathan/rivet/cli/target/debug/rivet-cli" ;
180162 }
181163
164+ // private static Result<JObject> RunRivetCLI(params string[] args)
165+ // {
166+ // // TODO: Turn this on if debug is enabled
167+ // RivetLogger.Log($"Running Rivet CLI: {GetRivetCLIPath()} {string.Join(" ", args)}");
168+
169+ // if (!File.Exists(GetRivetCLIPath()))
170+ // {
171+ // return new ResultErr<JObject>("File does not exist: " + GetRivetCLIPath());
172+ // }
173+
174+ // var startInfo = new ProcessStartInfo
175+ // {
176+ // FileName = GetRivetCLIPath(),
177+ // RedirectStandardOutput = true,
178+ // RedirectStandardError = true,
179+ // UseShellExecute = false,
180+ // CreateNoWindow = true,
181+ // };
182+ // foreach (var arg in args) {
183+ // startInfo.ArgumentList.Add(arg);
184+ // }
185+
186+ // try
187+ // {
188+ // using var process = Process.Start(startInfo);
189+ // var stdout = process.StandardOutput.ReadToEnd();
190+ // var stderr = process.StandardError.ReadToEnd();
191+ // process.WaitForExit();
192+
193+ // RivetLogger.Log($"Process output:\n\n{stdout}\n\n{stderr}");
194+
195+ // if (process.ExitCode == 0)
196+ // {
197+ // return new ResultOk<JObject>(JObject.Parse(stdout));
198+ // }
199+ // else
200+ // {
201+ // return new ResultErr<JObject>($"Process failed with exit code {process.ExitCode}\n\nstdout:\n{stdout}\n\nstderr:\n{stderr}");
202+ // }
203+ // }
204+ // catch (System.Exception ex)
205+ // {
206+ // return new ResultErr<JObject>("Failed to start process: " + ex.Message);
207+ // }
208+
209+ // }
210+
182211 public void Kill ( )
183212 {
184213 if ( ! IsRunning ) return ;
0 commit comments