Skip to content

Commit

Permalink
introduced cancel boolean message parameter "CancelCompleteTask" for …
Browse files Browse the repository at this point in the history
…a less strict cancelation message, where not all sub tasks will be canceled.
  • Loading branch information
Achim Ismaili committed Jul 12, 2018
1 parent b08f85c commit 66966fc
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/FeatureAdmin/Actors/FeatureDefinitionActor.cs
Expand Up @@ -48,6 +48,7 @@ private void LoadFarmFeatures(LoadFeatureDefinitionQuery message)
var cancelationMsg = new CancelMessage(
message.TaskId,
"Error loading feature definitions.",
true,
ex
);

Expand Down
16 changes: 10 additions & 6 deletions src/FeatureAdmin/Actors/LocationActor.cs
Expand Up @@ -117,7 +117,8 @@ private void ReceiveFeatureToggleRequest(FeatureToggleRequest message)
{
var cancelationMsg = new CancelMessage(
message.TaskId,
errorMsg
errorMsg,
true
);

Sender.Tell(cancelationMsg);
Expand Down Expand Up @@ -178,7 +179,8 @@ private void ReceiveFeatureToggleRequest(FeatureToggleRequest message)
{
var cancelationMsg = new CancelMessage(
message.TaskId,
errorMsg
errorMsg,
true
);

Sender.Tell(cancelationMsg);
Expand All @@ -188,10 +190,11 @@ private void ReceiveFeatureToggleRequest(FeatureToggleRequest message)
catch (Exception ex)
{
var cancelationMsg = new CancelMessage(
message.TaskId,
errorMsg,
ex
);
message.TaskId,
errorMsg,
true,
ex
);

Sender.Tell(cancelationMsg);
}
Expand Down Expand Up @@ -235,6 +238,7 @@ private void ReceiveLoadChildLocationQuery(LoadChildLocationQuery message)
var cancelationMsg = new CancelMessage(
message.TaskId,
"Error loading farm hierarchy." + tip,
true,
ex
);

Expand Down
6 changes: 5 additions & 1 deletion src/FeatureAdmin/Actors/Tasks/BaseTaskActor.cs
Expand Up @@ -30,7 +30,11 @@ protected override void ReceiveCancelMessage(CancelMessage message)
{
if (!TaskCanceled) // prevent multiple log entries
{
HandleCancelation(message);
if (message.CancelCompleteTask)
{
HandleCancelation(message);
}

Status = TaskStatus.Canceled;
CancelationMessage = message.CancelationMessage;
End = DateTime.Now;
Expand Down
23 changes: 18 additions & 5 deletions src/FeatureAdmin/Actors/Tasks/LoadTaskActor.cs
Expand Up @@ -160,6 +160,10 @@ public bool TrackLocationsProcessed(LoadedDto loadedMessage)
return finished;
}

/// <summary>
/// send cancelation message to all sub actors
/// </summary>
/// <param name="cancelMessage"></param>
protected override void HandleCancelation(FeatureAdmin.Messages.CancelMessage cancelMessage)
{
farmLoadActor.Tell(cancelMessage);
Expand Down Expand Up @@ -197,17 +201,26 @@ private void InitiateLoadTask(LoadTask loadTask)
// cleanup repository
if (loadTask.StartLocation.Scope == Enums.Scope.Farm)
{
// clear repository synchronous before loading
repository.Clear();

// initiate read of all feature definitions
var fdQuery = new Messages.Request.LoadFeatureDefinitionQuery(Id);
featureDefinitionActor.Tell(fdQuery);

// it could take some time to clear the repository, and errors could happen,
// so the task could be canceled meanwhile ...
if (!TaskCanceled)
{
// initiate read of all feature definitions
var fdQuery = new Messages.Request.LoadFeatureDefinitionQuery(Id);


featureDefinitionActor.Tell(fdQuery);


// initiate read of farm location, start location is null
var loadFarm = new LoadChildLocationQuery(Id, null, elevatedPrivileges);


farmLoadActor.Tell(loadFarm);

}
}
else
{
Expand Down
6 changes: 1 addition & 5 deletions src/FeatureAdmin/FeatureAdmin.csproj
Expand Up @@ -39,7 +39,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;SP2013</DefineConstants>
<DefineConstants>TRACE;DEBUG;DEMO</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
Expand Down Expand Up @@ -325,10 +325,6 @@
<Project>{e4a06935-054f-446a-b2af-996dc615d775}</Project>
<Name>Demo</Name>
</ProjectReference>
<ProjectReference Include="..\Backends\Sp2013\Sp2013.csproj">
<Project>{5d1949a6-17ed-4203-98f8-2b82415f97c1}</Project>
<Name>Sp2013</Name>
</ProjectReference>
<ProjectReference Include="..\FeatureAdmin.Core\FeatureAdmin.Core.csproj">
<Project>{4cec2e98-5a3b-4793-b606-a5250d046f02}</Project>
<Name>FeatureAdmin.Core</Name>
Expand Down
8 changes: 7 additions & 1 deletion src/FeatureAdmin/Messages/CancelMessage.cs
Expand Up @@ -8,9 +8,10 @@ namespace FeatureAdmin.Messages
{
public class CancelMessage
{
public CancelMessage(Guid taskId, string cancelationMessage, Exception ex = null)
public CancelMessage(Guid taskId, string cancelationMessage, bool cancelCompleteTask, Exception ex = null)
{
TaskId = taskId;
CancelCompleteTask = cancelCompleteTask;

if (ex != null && !string.IsNullOrEmpty(ex.Message))
{
Expand All @@ -24,6 +25,11 @@ public CancelMessage(Guid taskId, string cancelationMessage, Exception ex = null
}
}

/// <summary>
/// if set to false, other tasks in taskmanager will not be canceled
/// </summary>
public bool CancelCompleteTask { get; set; }

public Guid TaskId { get; private set; }

public Core.Models.Enums.LogLevel LogLevel { get; private set; }
Expand Down

0 comments on commit 66966fc

Please sign in to comment.