Skip to content

Commit

Permalink
DEV: Unload services (#1676)
Browse files Browse the repository at this point in the history
* Added script for test work queues
* Added a method to stop service tasks before unloading to avoid exceptions when unloading all services
* File renamed to match interface inside
* New interface IBackgroundService
* Moved script to new deployment version because the version 1.0.0 does not depend on the Security package
* Moved misplaced deployment script used for internal testing only so this should not be a problem
* Moved deployment script to a new version
  • Loading branch information
JindrichSusen committed Jul 10, 2023
1 parent 094b9e0 commit 0e548c7
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 61 deletions.
2 changes: 1 addition & 1 deletion backend/Origam.OrigamEngine/OrigamEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ public static void InitializeRuntimeServices()

public static void UnloadConnectedServices()
{
RestartTimer?.Stop();
serviceFactory.UnloadServices();
DataServiceFactory.ClearDataService();
}

public static void DisconnectRuntime()
{
UnloadConnectedServices();
RestartTimer?.Stop();
}

public static void ConnectRuntime(
Expand Down
49 changes: 27 additions & 22 deletions backend/Origam.OrigamEngine/RuntimeServiceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
#endregion

using System.Collections.Generic;
using System.Linq;
using Origam.DA;
using Origam.DA.Service.MetaModelUpgrade;
using Origam.Rule;
Expand Down Expand Up @@ -60,28 +62,31 @@ public void InitializeServices()
}
public void UnloadServices()
{
IWorkbenchService persistence = ServiceManager.Services.GetService(typeof(IPersistenceService));
IWorkbenchService stateMachine = ServiceManager.Services.GetService(typeof(IStateMachineService));
IBusinessServicesService serviceAgent = ServiceManager.Services.GetService(typeof(IBusinessServicesService)) as IBusinessServicesService;
IWorkbenchService documentation = ServiceManager.Services.GetService(typeof(IDocumentationService));
IWorkbenchService tracing = ServiceManager.Services.GetService(typeof(TracingService));
IDataLookupService dataLookupService = ServiceManager.Services.GetService(typeof(IDataLookupService)) as IDataLookupService;
IWorkbenchService parameter = ServiceManager.Services.GetService(typeof(IParameterService));
IWorkbenchService deployment = ServiceManager.Services.GetService(typeof(IDeploymentService));
IWorkbenchService workQueue = ServiceManager.Services.GetService(typeof(IWorkQueueService));
IWorkbenchService attachment = ServiceManager.Services.GetService(typeof(IAttachmentService));
IWorkbenchService ruleEngine = ServiceManager.Services.GetService(typeof(IRuleEngineService));
ServiceManager.Services.UnloadService(stateMachine);
ServiceManager.Services.UnloadService(parameter);
ServiceManager.Services.UnloadService(deployment);
ServiceManager.Services.UnloadService(dataLookupService);
ServiceManager.Services.UnloadService(tracing);
ServiceManager.Services.UnloadService(documentation);
ServiceManager.Services.UnloadService(serviceAgent);
ServiceManager.Services.UnloadService(persistence);
ServiceManager.Services.UnloadService(attachment);
ServiceManager.Services.UnloadService(ruleEngine);
ServiceManager.Services.UnloadService(workQueue);
List<IWorkbenchService> services = new []
{
typeof(IPersistenceService),
typeof(IStateMachineService),
typeof(IBusinessServicesService),
typeof(IDocumentationService),
typeof(TracingService),
typeof(IDataLookupService),
typeof(IParameterService),
typeof(IDeploymentService),
typeof(IWorkQueueService),
typeof(IAttachmentService),
typeof(IRuleEngineService),
}
.Select(ServiceManager.Services.GetService)
.ToList();
foreach (var service in services.OfType<IBackgroundService>())
{
service.StopTasks();
}
foreach (var service in services)
{
ServiceManager.Services.UnloadService(service);
}

}
protected virtual IParameterService CreateParameterService()
{
Expand Down
2 changes: 1 addition & 1 deletion backend/Origam.Rule/RuleEngineService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public RuleEngineService()
{
}
#region IWorkbenchService Members

public void UnloadService()
{
}
Expand Down
1 change: 0 additions & 1 deletion backend/Origam.Services/AbstractDocumentationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public void CloneDocumentation(List<ISchemaItem> clonedSchemaItems)
#region IWorkbenchService Members

public abstract void InitializeService();

public abstract void UnloadService();

public abstract event System.EventHandler Initialize;
Expand Down
5 changes: 2 additions & 3 deletions backend/Origam.Services/AbstractService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@

namespace Origam.Workbench.Services
{
public class AbstractService : IWorkbenchService
public abstract class AbstractService : IWorkbenchService
{
public virtual void InitializeService()
{
OnInitialize(EventArgs.Empty);
}



public virtual void UnloadService()
{
OnUnload(EventArgs.Empty);
Expand Down
9 changes: 9 additions & 0 deletions backend/Origam.Services/IBackgroundService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Origam.Workbench.Services;

public interface IBackgroundService
{
// Should stop timers and other running tasks. This is useful when
// unloading all services because they depend on each other. Not
// stopping all tasks before calling UnloadService would result in exceptions.
void StopTasks();
}
File renamed without changes.
2 changes: 1 addition & 1 deletion backend/Origam.Workbench.Services/ParameterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ private Hashtable LanguageResolveDict
#endregion

#region IWorkbenchService Members

public void UnloadService()
{
if (_schemaService != null)
Expand Down
2 changes: 1 addition & 1 deletion backend/Origam.Workbench.Services/ServiceAgentFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public IServiceAgent GetAgent(string serviceType, string instanceName, object ru
#endregion

#region IService Members

public void UnloadService()
{
_persistence = null;
Expand Down
8 changes: 4 additions & 4 deletions backend/Origam.Workflow/WorkQueue/WorkQueueService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace Origam.Workflow.WorkQueue
/// <summary>
/// Summary description for WorkQueueService.
/// </summary>
public class WorkQueueService : IWorkQueueService
public class WorkQueueService : IWorkQueueService, IBackgroundService
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private const string WQ_EVENT_ONCREATE = "fe40902f-8a44-477e-96f9-d157eee16a0f";
Expand Down Expand Up @@ -114,10 +114,10 @@ public void UnloadService()
schemaService.SchemaLoaded -= schemaService_SchemaLoaded;
schemaService.SchemaUnloaded -= schemaService_SchemaUnloaded;
schemaService.SchemaUnloading -= schemaService_SchemaUnloading;
StopTimers();
StopTasks();
}

private void StopTimers()
public void StopTasks()
{
if(log.IsDebugEnabled)
{
Expand Down Expand Up @@ -1825,7 +1825,7 @@ void schemaService_SchemaUnloading(object sender, CancelEventArgs e)
{
log.Debug("schemaService_SchemaUnloading");
}
StopTimers();
StopTasks();
}

void schemaService_SchemaUnloaded(object sender, EventArgs e)
Expand Down
4 changes: 1 addition & 3 deletions backend/Origam.WorkflowTests/WorkQueueIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ public void OneTimeSetUp()
public void TearDown()
{
sqlManager.DeleteWorkQueueEntries();
Console.WriteLine(
"\nRunning DisconnectRuntime. There might be some errors logged here. " +
"These are probably not a problem.\n");
Console.WriteLine("\nRunning DisconnectRuntime.");
OrigamEngine.OrigamEngine.DisconnectRuntime();
}

Expand Down
2 changes: 1 addition & 1 deletion model-tests/model/AutomaticTests/.origamPackage
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
x:id="c130ecd2-3b61-48fe-bac0-b721f86b0a0f"
x:isFolder="true"
p:name="AutomaticTests"
p:version="1.0.1">
p:version="1.0.2">
<pr:packageReference
x:id="db67be0a-ccca-4869-a2ea-426d7669c73e"
pr:referencedPackage="Widgets/.origamPackage#f17329d6-3143-420a-a2e6-30e431eea51d" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<x:file
xmlns:x="http://schemas.origam.com/model-persistence/1.0.0"
xmlns:asi="http://schemas.origam.com/Origam.Schema.AbstractSchemaItem/6.0.0"
xmlns:ausa="http://schemas.origam.com/Origam.Schema.DeploymentModel.AbstractUpdateScriptActivity/6.0.0"
xmlns:dv="http://schemas.origam.com/Origam.Schema.DeploymentModel.DeploymentVersion/6.0.0"
xmlns:scusa="http://schemas.origam.com/Origam.Schema.DeploymentModel.ServiceCommandUpdateScriptActivity/6.0.0">
<dv:DeploymentVersion
asi:abstract="false"
dv:deploymentDependenciesCsv="&#xD;&#xA;147fa70d-6519-4393-b5d0-87931f9fd609, 5.3.1&#xD;&#xA;951f2cda-2867-4b99-8824-071fa8749ead, 5.4.1&#xD;&#xA;b9ab12fe-7f7d-43f7-bedc-93747647d6e4, 1.2.3&#xD;&#xA;bb8c67fb-44c1-4b41-8fce-4d50cd5a759d, 1.0.0&#xD;&#xA;255eec22-89c5-479a-b48d-e7bc9baa564a, 1.0.0"
x:id="79f10e6a-66c3-4eb5-8476-94b3585513db"
asi:name="1.5.5"
dv:version="1.5.5">
<scusa:DeploymentUpdateScriptActivity
asi:abstract="false"
ausa:activityOrder="10"
scusa:commandText="-***-ExternalFile:1.5.5.origam___commandText___924f5d51-7571-4d7d-ba4a-0c5b44f91c63.txt"
x:id="924f5d51-7571-4d7d-ba4a-0c5b44f91c63"
asi:name="00010_Script_TestWorkQueuesWithCommands"
scusa:platform="MsSql"
scusa:service="Root/Service/DataService.origam#DataService/bbd7bd32-d40b-441a-bb5b-0b0fa89169d4" />
</dv:DeploymentVersion>
<?xml version="1.0" encoding="utf-8"?>
<x:file
xmlns:x="http://schemas.origam.com/model-persistence/1.0.0"
xmlns:asi="http://schemas.origam.com/Origam.Schema.AbstractSchemaItem/6.0.0"
xmlns:ausa="http://schemas.origam.com/Origam.Schema.DeploymentModel.AbstractUpdateScriptActivity/6.0.0"
xmlns:dv="http://schemas.origam.com/Origam.Schema.DeploymentModel.DeploymentVersion/6.0.0"
xmlns:scusa="http://schemas.origam.com/Origam.Schema.DeploymentModel.ServiceCommandUpdateScriptActivity/6.0.0">
<dv:DeploymentVersion
asi:abstract="false"
dv:deploymentDependenciesCsv="&#xD;&#xA;147fa70d-6519-4393-b5d0-87931f9fd609, 5.3.1&#xD;&#xA;951f2cda-2867-4b99-8824-071fa8749ead, 5.4.1&#xD;&#xA;b9ab12fe-7f7d-43f7-bedc-93747647d6e4, 1.2.3&#xD;&#xA;bb8c67fb-44c1-4b41-8fce-4d50cd5a759d, 1.0.0&#xD;&#xA;255eec22-89c5-479a-b48d-e7bc9baa564a, 1.0.0&#xD;&#xA;f17329d6-3143-420a-a2e6-30e431eea51d, 1.5.4"
x:id="6641da92-8557-48e0-aef5-6cd94111a6d6"
asi:name="1.0.2"
dv:version="1.0.2">
<scusa:DeploymentUpdateScriptActivity
asi:abstract="false"
ausa:activityOrder="10"
scusa:commandText="-***-ExternalFile:1.0.2.origam___commandText___785f017c-e4a4-4a00-bf9d-c37cd842f382.txt"
x:id="785f017c-e4a4-4a00-bf9d-c37cd842f382"
asi:name="00010_InsertWorkqueuesAndCommandsForTests"
scusa:platform="MsSql"
scusa:service="Root/Service/DataService.origam#DataService/bbd7bd32-d40b-441a-bb5b-0b0fa89169d4" />
</dv:DeploymentVersion>
</x:file>
2 changes: 1 addition & 1 deletion model-tests/model/Widgets/.origamPackage
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
x:id="f17329d6-3143-420a-a2e6-30e431eea51d"
x:isFolder="true"
p:name="Widgets"
p:version="1.5.5">
p:version="1.5.4">
<pr:packageReference
x:id="3de8351f-ea09-4ffd-a5eb-f847b4355614"
pr:referencedPackage="Root/.origamPackage#147fa70d-6519-4393-b5d0-87931f9fd609" />
Expand Down

0 comments on commit 0e548c7

Please sign in to comment.