Skip to content

Commit

Permalink
Merge pull request #791 from skadefro/master
Browse files Browse the repository at this point in the history
add thread_exit_on_lock_timeout / fix restore_dependencies_on_startup…
  • Loading branch information
skadefro authored Aug 2, 2024
2 parents ab5b900 + f6be4bb commit ab7263b
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 24 deletions.
2 changes: 2 additions & 0 deletions OpenRPA.Interfaces/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class Config
public bool disable_instance_store { get { return GetProperty(null, false); } set { SetProperty(null, value); } }
public bool skip_online_state { get { return GetProperty(null, false); } set { SetProperty(null, value); } }
public int thread_lock_timeout_seconds { get { return GetProperty(null, 10); } set { SetProperty(null, value); } }
public bool thread_exit_on_lock_timeout { get { return GetProperty(null, false); } set { SetProperty(null, value); } }
public bool skip_child_session_check { get { return GetProperty(null, false); } set { SetProperty(null, value); } }
private void loadEntropy()
{
Expand Down Expand Up @@ -258,6 +259,7 @@ public void Save(string filename)
_ = skip_online_state;
_ = thread_lock_timeout_seconds;
_ = skip_child_session_check;
_ = thread_exit_on_lock_timeout;

_ = max_trace_lines;
_ = max_output_lines;
Expand Down
2 changes: 1 addition & 1 deletion OpenRPA/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ private async void Application_Startup(object sender, StartupEventArgs e)
}
}

if (Config.local.restoreDependenciesOnStartup)
if (Config.local.restore_dependencies_on_startup)
{
Log.Debug("Package restore on startup enabled -> cleaning existing extensions.");
var extensionsPath = Path.Combine(Interfaces.Extensions.ProjectsDirectory, "extensions");
Expand Down
31 changes: 24 additions & 7 deletions OpenRPA/Detector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,19 @@ public async Task Save(bool skipOnline = false)
System.Threading.Monitor.Exit(RobotInstance.instance.Detectors);
}
}
else { throw new LockNotReceivedException("Saving detector"); }
else
{
if (Config.local.thread_exit_on_lock_timeout)
{
Log.Error("Locally Cached savelock");
System.Environment.Exit(1);
}
throw new LockNotReceivedException("Saving detector");
}
}
public async Task Delete(bool skipOnline = false)
{
if(!skipOnline) await Delete<Detector>();
if (!skipOnline) await Delete<Detector>();
if (System.Threading.Monitor.TryEnter(RobotInstance.instance.Detectors, Config.local.thread_lock_timeout_seconds * 1000))
{
try
Expand All @@ -72,7 +80,15 @@ public async Task Delete(bool skipOnline = false)
System.Threading.Monitor.Exit(RobotInstance.instance.Detectors);
}
}
else { throw new LockNotReceivedException("Deleting detector"); }
else
{
if (Config.local.thread_exit_on_lock_timeout)
{
Log.Error("Locally Cached savelock");
System.Environment.Exit(1);
}
throw new LockNotReceivedException("Deleting detector");
}
}
public void ExportFile(string filepath)
{
Expand All @@ -91,12 +107,13 @@ public void Start(bool doRegisterExchange)
return;
}
}
if(doRegisterExchange) _ = RegisterExchange();
if(RobotInstance.instance != null && RobotInstance.instance.Window != null)
if (doRegisterExchange) _ = RegisterExchange();
if (RobotInstance.instance != null && RobotInstance.instance.Window != null)
{
dp.OnDetector -= RobotInstance.instance.Window.OnDetector;
dp.OnDetector += RobotInstance.instance.Window.OnDetector;
} else
}
else
{
Log.Error("Failed registering detector event sink for " + name + " main window not loaded yet !!!!!");
}
Expand All @@ -113,7 +130,7 @@ async public Task RegisterExchange()
var reqver = Version.Parse("1.3.103"); // exchange support for detectors was not added until 1.3.103
if (ver < reqver) return;
if (dp.Entity != null && dp.Entity.detectortype == "exchange" && !string.IsNullOrEmpty(dp.Entity._id))
{
{
await global.webSocketClient.RegisterExchange(dp.Entity._id, "fanout", false, "", "");
}
}
Expand Down
27 changes: 24 additions & 3 deletions OpenRPA/LocallyCached.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,14 @@ public async Task Save<T>(bool skipOnline = false) where T : apibase
System.Threading.Monitor.Exit(savelock);
}
}
else { throw new LockNotReceivedException("Locally Cached savelock"); }
else {
if(Config.local.thread_exit_on_lock_timeout)
{
Log.Error("Locally Cached savelock");
System.Environment.Exit(1);
}
throw new LockNotReceivedException("Locally Cached savelock");
}
}
catch (Exception)
{
Expand Down Expand Up @@ -173,7 +180,14 @@ public async Task Delete<T>() where T : apibase
System.Threading.Monitor.Exit(savelock);
}
}
else { throw new LockNotReceivedException("Locally Cached savelock"); }
else {
if (Config.local.thread_exit_on_lock_timeout)
{
Log.Error("Locally Cached savelock");
System.Environment.Exit(1);
}
throw new LockNotReceivedException("Locally Cached savelock");
}
}
catch (Exception ex)
{
Expand All @@ -199,7 +213,14 @@ public async Task Delete<T>() where T : apibase
System.Threading.Monitor.Exit(savelock);
}
}
else { throw new LockNotReceivedException("Locally Cached savelock"); }
else {
if (Config.local.thread_exit_on_lock_timeout)
{
Log.Error("Locally Cached savelock");
System.Environment.Exit(1);
}
throw new LockNotReceivedException("Locally Cached savelock");
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion OpenRPA/OpenRPA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Description>Base UI of OpenRPA, used as part of OpenRPA robot</Description>
<PackageLicenseExpression>MPL-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/open-rpa/openrpa</PackageProjectUrl>
<Version>1.4.57.7</Version>
<Version>1.4.57.8</Version>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageIcon>openrpa.png</PackageIcon>
<Configurations>Debug;Release;ReleaseNuget;PrepInstaller</Configurations>
Expand Down
18 changes: 16 additions & 2 deletions OpenRPA/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,14 @@ public async Task Save(bool skipOnline = false)
System.Threading.Monitor.Exit(RobotInstance.instance.Projects);
}
}
else { throw new LockNotReceivedException("Saving Project"); }
else {
if (Config.local.thread_exit_on_lock_timeout)
{
Log.Error("Locally Cached savelock");
System.Environment.Exit(1);
}
throw new LockNotReceivedException("Saving Project");
}
});
}
public async Task Update(IProject item, bool skipOnline = false)
Expand Down Expand Up @@ -483,7 +490,14 @@ public async Task Delete(bool skipOnline = false)
System.Threading.Monitor.Exit(RobotInstance.instance.Projects);
}
}
else { throw new LockNotReceivedException("Delete Project"); }
else {
if (Config.local.thread_exit_on_lock_timeout)
{
Log.Error("Locally Cached savelock");
System.Environment.Exit(1);
}
throw new LockNotReceivedException("Delete Project");
}
});
}
public override string ToString()
Expand Down
12 changes: 9 additions & 3 deletions OpenRPA/RobotInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ public bool isRunningInChildSession
}
}
}
private static readonly object statelock = new object();
public IMainWindow Window { get; set; }
public List<IWorkflowInstance> WorkflowInstances
{
Expand All @@ -161,7 +160,14 @@ public List<IWorkflowInstance> WorkflowInstances
System.Threading.Monitor.Exit(WorkflowInstance.Instances);
}
}
else { throw new LockNotReceivedException("Failed returning list of workflow instances"); }
else {
if (Config.local.thread_exit_on_lock_timeout)
{
Log.Error("Locally Cached savelock");
System.Environment.Exit(1);
}
throw new LockNotReceivedException("Failed returning list of workflow instances");
}
return result;
}
}
Expand Down Expand Up @@ -770,7 +776,7 @@ await GenericTools.RunUIAsync(async () =>
{
// just started a new instance, load all project dependencies
first_serverDataLoad = false;
if (Config.local.restoreDependenciesOnStartup)
if (Config.local.restore_dependencies_on_startup)
{
try
{
Expand Down
18 changes: 16 additions & 2 deletions OpenRPA/Store/AsyncResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ public WaitHandle AsyncWaitHandle
System.Threading.Monitor.Exit(ThisLock);
}
}
else { throw new LockNotReceivedException("Async ThisLock"); }
else {
if (Config.local.thread_exit_on_lock_timeout)
{
Interfaces.Log.Error("Locally Cached savelock");
System.Environment.Exit(1);
}
throw new LockNotReceivedException("Async ThisLock");
}
return manualResetEvent;
}
}
Expand Down Expand Up @@ -125,7 +132,14 @@ protected void Complete(bool completedSynchronously)
System.Threading.Monitor.Exit(ThisLock);
}
}
else { throw new LockNotReceivedException("Async ThisLock"); }
else {
if (Config.local.thread_exit_on_lock_timeout)
{
Interfaces.Log.Error("Locally Cached savelock");
System.Environment.Exit(1);
}
throw new LockNotReceivedException("Async ThisLock");
}
}
if (callback != null)
{
Expand Down
18 changes: 16 additions & 2 deletions OpenRPA/Workflow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,14 @@ public async Task Save(bool skipOnline = false)
System.Threading.Monitor.Exit(RobotInstance.instance.Workflows);
}
}
else { throw new LockNotReceivedException("Failed saving workflow"); }
else {
if (Config.local.thread_exit_on_lock_timeout)
{
Log.Error("Locally Cached savelock");
System.Environment.Exit(1);
}
throw new LockNotReceivedException("Failed saving workflow");
}
}
public async Task Update(IWorkflow item, bool skipOnline = false)
{
Expand Down Expand Up @@ -468,7 +475,14 @@ public async Task Delete(bool skipOnline = false)
System.Threading.Monitor.Exit(RobotInstance.instance.Workflows);
}
}
else { throw new LockNotReceivedException("Failed deleting workflow"); }
else {
if (Config.local.thread_exit_on_lock_timeout)
{
Log.Error("Locally Cached savelock");
System.Environment.Exit(1);
}
throw new LockNotReceivedException("Failed deleting workflow");
}
}
catch (Exception ex)
{
Expand Down
27 changes: 24 additions & 3 deletions OpenRPA/WorkflowInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,14 @@ public static WorkflowInstance Create(Workflow Workflow, Dictionary<string, obje
System.Threading.Monitor.Exit(Instances);
}
}
else { throw new LockNotReceivedException("Failed adding new workflow instance in Create"); }
else {
if (Config.local.thread_exit_on_lock_timeout)
{
Log.Error("Locally Cached savelock");
System.Environment.Exit(1);
}
throw new LockNotReceivedException("Failed adding new workflow instance in Create");
}
try
{
result.createApp(Workflow.Activity());
Expand Down Expand Up @@ -743,7 +750,14 @@ public void Run()
System.Threading.Monitor.Exit(Instances);
}
}
else { throw new LockNotReceivedException("Failed running workflow instance"); }
else {
if (Config.local.thread_exit_on_lock_timeout)
{
Log.Error("Locally Cached savelock");
System.Environment.Exit(1);
}
throw new LockNotReceivedException("Failed running workflow instance");
}
}
else
{
Expand Down Expand Up @@ -1065,7 +1079,14 @@ public static void CleanUp()
Log.Error(ex.ToString());
}
}
else { throw new LockNotReceivedException("Failed cleaning up old workflow instance"); }
else {
if (Config.local.thread_exit_on_lock_timeout)
{
Log.Error("Locally Cached savelock");
System.Environment.Exit(1);
}
throw new LockNotReceivedException("Failed cleaning up old workflow instance");
}
}
public override string ToString()
{
Expand Down

0 comments on commit ab7263b

Please sign in to comment.