Skip to content

Commit

Permalink
v1.4.0-beta.55
Browse files Browse the repository at this point in the history
- Removed operation lock and "spawning too fast" check from ProgramBlock (not necessary anymore)
- Fixes excessive refresh rate of Weather Widget slowing down the UI
  • Loading branch information
genemars committed Sep 27, 2023
1 parent 1c2d222 commit 6347445
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 59 deletions.
2 changes: 2 additions & 0 deletions assets/build/all/app/assets/i18n/homegenie/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@
"Stop program",
"run_program":
"Run program",
"enable_to_run_program":
"Enable program in order to run it",
"program_status_added":
"Added",
"program_status_idle":
Expand Down
2 changes: 2 additions & 0 deletions assets/build/all/app/assets/i18n/homegenie/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@
"Interrompi programma",
"run_program":
"Esegui programma",
"enable_to_run_program":
"Abilita il programma per eseguirlo",
"program_status_added":
"Aggiunto",
"program_status_idle":
Expand Down
2 changes: 1 addition & 1 deletion assets/build/all/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@

</div>

<script src="runtime.b92e2ca178ebbf4a.js" type="module"></script><script src="polyfills.a360d6e45b80c065.js" type="module"></script><script src="scripts.0dcb4f0a61221c18.js" defer></script><script src="main.a56a8879565d6386.js" type="module"></script>
<script src="runtime.b92e2ca178ebbf4a.js" type="module"></script><script src="polyfills.a360d6e45b80c065.js" type="module"></script><script src="scripts.0dcb4f0a61221c18.js" defer></script><script src="main.a1d44682d6be2112.js" type="module"></script>

</body></html>

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions assets/build/all/app/ngsw.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"configVersion": 1,
"timestamp": 1695734403275,
"timestamp": 1695799237981,
"index": "/app/index.html",
"assetGroups": [
{
Expand All @@ -15,7 +15,7 @@
"/app/613.16b9c52c0ae74833.js",
"/app/859.0f150be9c99a6b5a.js",
"/app/index.html",
"/app/main.a56a8879565d6386.js",
"/app/main.a1d44682d6be2112.js",
"/app/manifest.webmanifest",
"/app/polyfills.a360d6e45b80c065.js",
"/app/runtime.b92e2ca178ebbf4a.js",
Expand Down Expand Up @@ -445,8 +445,8 @@
"/app/assets/fonts/Roboto-Latin-400.woff": "fec6225507c70951797db15985fe0bf87195d6ee",
"/app/assets/fonts/Roboto-Latin-500.woff": "7416b5d46c615d2786a604d71d334b605d41cc73",
"/app/assets/i18n/en.json": "2c102d1542c09ccfc2345de7627fbd5bde485ff4",
"/app/assets/i18n/homegenie/en.json": "46fcd188f209a020c910554303938787b4fa85e9",
"/app/assets/i18n/homegenie/it.json": "63d300c523536bf726e903f28f85f3b5f58d383d",
"/app/assets/i18n/homegenie/en.json": "6649ad3f42798cb72c0786ddc23190ed6cfbf3d7",
"/app/assets/i18n/homegenie/it.json": "5f382a852cd94571d6511f2e79ca2c7f43ed98fd",
"/app/assets/i18n/it.json": "5417c8b3739e34282dc2d1424c31d94aea2a79ff",
"/app/assets/i18n/module/en.json": "bd1f58f6eeb2e8213bc5dbe316d1252db8aa436f",
"/app/assets/i18n/module/it.json": "35c4ef9b17591c0ef0283317a3f226c666d908f9",
Expand Down Expand Up @@ -759,8 +759,8 @@
"/app/assets/widgets/weather/images_alt/thunder.svg": "2ace7038dfd663330cecc350d680ef08206d62ff",
"/app/assets/widgets/weather/images_alt/weather.svg": "c719c09048977fd40688272316b35ddf1bdf89e8",
"/app/assets/workers/typings-worker.js": "8df10d867c12d36cdebfb7e16caacd0020db301f",
"/app/index.html": "3844bbfa3d6ad67e22c218104dc46a3e4a8e2c33",
"/app/main.a56a8879565d6386.js": "ca58448e7d1f2d0de714340270f538d1dc305ffd",
"/app/index.html": "1aa69ee79a288f87d06a4e4af7f57b96de315c64",
"/app/main.a1d44682d6be2112.js": "1ef00a5d9d127f9d7c3afc6561fd44674214a140",
"/app/manifest.webmanifest": "d47bb07a495e27ddf072f8702df373f79b4eb183",
"/app/polyfills.a360d6e45b80c065.js": "f317e1a3e4bb6a84068c7e1845a2ce8b2f956ee7",
"/app/runtime.b92e2ca178ebbf4a.js": "b50d841a4c50d466c34aab3267d3fb4afe87dede",
Expand Down
77 changes: 28 additions & 49 deletions src/HomeGenie/Automation/Engines/ProgramEngineBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ You should have received a copy of the GNU General Public License
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;

using Newtonsoft.Json;

Expand Down Expand Up @@ -110,6 +111,9 @@ public void StartProgram(string options = null)
StopProgram();
}

if (!ProgramBlock.IsEnabled)
return;

ProgramBlock.IsRunning = true;
HomeGenie.ProgramManager.RaiseProgramModuleEvent(ProgramBlock, Properties.ProgramStatus, "Running");

Expand Down Expand Up @@ -187,7 +191,6 @@ public void StartProgram(string options = null)
StopProgram();
HomeGenie.ProgramManager.RaiseProgramModuleEvent(ProgramBlock, Properties.ProgramStatus, "Idle");
}
lastProgramRunTs = DateTime.Now;
}

public void StopProgram()
Expand Down Expand Up @@ -267,10 +270,6 @@ public void RegisterDynamicApi(string apiCall, Func<object, object> handler)

#endregion

private int loopPreventCount = 0;
private readonly int loopPreventMax = 50;
private DateTime lastProgramRunTs = DateTime.Now;

private void CheckProgramSchedule()
{
// set initial state to signaled
Expand All @@ -293,33 +292,15 @@ private void CheckProgramSchedule()
{
continue;
}
if (WillProgramRun())
// Run asynchronously to prevent RoutedEventAck loops
Task.Run(() =>
{
ProgramBlock.WillRun = false;
if ((DateTime.Now - lastProgramRunTs).TotalMilliseconds < 20)
loopPreventCount++;
else
loopPreventCount = 0;
if (loopPreventCount < loopPreventMax)
StartProgram(null);
else
if (ProgramBlock.IsEnabled && WillProgramRun())
{
var errorMessage = "Program has been disabled because it was looping/spawning too fast.";
List<ProgramError> error = new List<ProgramError>()
{
new ProgramError()
{
CodeBlock = CodeBlockEnum.TC,
ErrorNumber = "0",
ErrorMessage = errorMessage
}
};
ProgramBlock.ScriptErrors = JsonConvert.SerializeObject(error);
ProgramBlock.IsEnabled = false;
HomeGenie.ProgramManager.RaiseProgramModuleEvent(ProgramBlock, Properties.RuntimeError,
CodeBlockEnum.TC + errorMessage);
ProgramBlock.WillRun = false;
StartProgram(null);
}
}
}).Wait();
}
}

Expand All @@ -329,40 +310,38 @@ private bool WillProgramRun()
// evaluate and get result from the setup code
try
{
lock (ProgramBlock.OperationLock)
var result = Setup();
if (result != null && result.Exception != null)
{
var result = Setup();
if (result != null && result.Exception != null)
{
// runtime error occurred, script is being disabled
// so user can notice and fix it
var error = new List<ProgramError> {GetFormattedError(result.Exception, true)};
ProgramBlock.ScriptErrors = JsonConvert.SerializeObject(error);
_log.Error(result.Exception, "Error while running setup code in program {0}",
ProgramBlock.Address);
HomeGenie.ProgramManager.RaiseProgramModuleEvent(ProgramBlock, Properties.RuntimeError,
PrepareExceptionMessage(CodeBlockEnum.TC, result.Exception));
// runtime error occurred, script is being disabled
// so user can notice and fix it
var error = new List<ProgramError> {GetFormattedError(result.Exception, true)};
ProgramBlock.ScriptErrors = JsonConvert.SerializeObject(error);
_log.Error(result.Exception, "Error while running setup code in program {0}",
ProgramBlock.Address);
HomeGenie.ProgramManager.RaiseProgramModuleEvent(ProgramBlock, Properties.RuntimeError,
PrepareExceptionMessage(CodeBlockEnum.TC, result.Exception));

TryToAutoRestart();
}
else
{
isConditionSatisfied = (result != null ? (bool) result.ReturnValue : false);
}
TryToAutoRestart();
}
else
{
isConditionSatisfied = (result != null ? (bool) result.ReturnValue : false);
}
}
catch (Exception ex)
{
// a runtime error occured
if (ex.GetType() == typeof(TargetException) || ex is ThreadAbortException || ex is ThreadInterruptedException)
{
return isConditionSatisfied && ProgramBlock.IsEnabled;
}
// a runtime error occured
List<ProgramError> error = new List<ProgramError>() {GetFormattedError(ex, true)};
ProgramBlock.ScriptErrors = JsonConvert.SerializeObject(error);
HomeGenie.ProgramManager.RaiseProgramModuleEvent(ProgramBlock, Properties.RuntimeError,
PrepareExceptionMessage(CodeBlockEnum.TC, ex));
TryToAutoRestart();
}

return isConditionSatisfied && ProgramBlock.IsEnabled;
}

Expand Down
2 changes: 0 additions & 2 deletions src/HomeGenie/Automation/ProgramBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ public class ProgramBlock
public bool WillRun { get; set; }
[XmlIgnore]
public bool IsRunning { get; set; }
[XmlIgnore, JsonIgnore]
public object OperationLock = new object();

public ProgramBlock()
{
Expand Down

0 comments on commit 6347445

Please sign in to comment.