Skip to content

Commit

Permalink
fix(LocalRun): support silent mode
Browse files Browse the repository at this point in the history
  • Loading branch information
MingboPeng committed Aug 14, 2023
1 parent 371c8a5 commit e3ef4b9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/PollinationSDK/Helper/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -485,12 +485,17 @@ internal static void CopyDirectory(string sDir, string dDir)
/// Execute *.sh file on Mac or *.bat on Windows
/// </summary>
/// <param name="scriptFile"></param>
public static void RunScriptFile(string scriptFile)
public static void RunScriptFile(string scriptFile, bool silentMode)
{
if (!Utilities.IsMac)
{
//Windows
var p = System.Diagnostics.Process.Start(scriptFile);
var pInfo = new System.Diagnostics.ProcessStartInfo(scriptFile);
if (silentMode)
pInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

var p = System.Diagnostics.Process.Start(pInfo);

p.WaitForExit();
}
else //Mac
Expand Down
13 changes: 12 additions & 1 deletion src/PollinationSDK/Wrapper/JobInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class JobInfo
public string ProjectSlug { get; set; } // for cloud and local job, ladybug_tools/demoProject
public int LocalCPUNumber { get; set; } // for local job only
public string LocalRunFolder { get; set; } // for local job only
public bool LocalSilentMode { get; set; } // for local job only
public string Platform { get; set; } = "unknown"; // rhino, revit, grasshopper
public string LocalJobStatus { get; set; } = "unknown"; // RunStatusEnum for a local job

Expand Down Expand Up @@ -57,6 +58,15 @@ public void SetLocalJob(string projectOwner, string projectName, string runFolde
this.LocalCPUNumber = cpuNo;
}

public void SetLocalSilentMode(bool enableSilent)
{
if (this.IsLocalJob)
this.LocalSilentMode = enableSilent;
else
throw new ArgumentException("Silent mode only works with local job! Call SetLocalJob() to set local job settings first!");

}

public void SetJobAuthor(AccountPublic authorAccount)
{
this.JobAuthor = authorAccount;
Expand Down Expand Up @@ -243,8 +253,9 @@ private async Task<ScheduledJobInfo> RunJobOnLocalAsync()

var workDir = this.LocalRunOutputFolder;
var cpuNum = this.LocalCPUNumber;
var isSilentMode = this.LocalSilentMode;
var runner = new JobRunner(this);
var runout = await Task.Run(() => runner.RunOnLocalMachine(workDir, cpuNum)).ConfigureAwait(false);
var runout = await Task.Run(() => runner.RunOnLocalMachine(workDir, cpuNum, isSilentMode)).ConfigureAwait(false);
// check local job status
var status = JobRunner.CheckLocalJobStatus(runout);
this.LocalJobStatus = status.ToString();
Expand Down
4 changes: 2 additions & 2 deletions src/PollinationSDK/Wrapper/JobRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public async Task<CloudJob> RunOnCloudAsync(Project project, Action<string> prog
}


public string RunOnLocalMachine(string workFolder, int workerNum)
public string RunOnLocalMachine(string workFolder, int workerNum, bool silentMode)
{
if (string.IsNullOrEmpty(Utilities.PythonRoot) || !Directory.Exists(Utilities.PythonRoot))
throw new ArgumentException("Missing some setting for local simulations, please use Utilities.SetPaths before running any local simulations");
Expand Down Expand Up @@ -189,7 +189,7 @@ public string RunOnLocalMachine(string workFolder, int workerNum)
File.WriteAllText(scriptFile, script);

// dealing with both windows and mac
Helper.RunScriptFile(scriptFile);
Helper.RunScriptFile(scriptFile, silentMode);
}
catch (Exception ex)
{
Expand Down

0 comments on commit e3ef4b9

Please sign in to comment.