Skip to content

Instantly share code, notes, and snippets.

@harrybiscuit
Created January 30, 2014 15:39
Show Gist options
  • Save harrybiscuit/8711258 to your computer and use it in GitHub Desktop.
Save harrybiscuit/8711258 to your computer and use it in GitHub Desktop.
A simple workflow application monitor
using System;
using System.Collections.Concurrent;
public interface IWorkflowApplicationMonitor
{
bool IsRunning(Guid workflowDefinitionId);
void SetStatusToRunning(Guid workflowDefinitionId);
void SetStatusToNotRunning(Guid workflowDefinitionId);
}
public class WorkflowApplicationMonitor : IWorkflowApplicationMonitor
{
public const bool IS_RUNNING_FLAG = true;
public const bool IS_NOT_RUNNING_FLAG = false;
private static readonly ConcurrentDictionary<Guid, bool> _runningWorkflowDefinitions =
new ConcurrentDictionary<Guid, bool>();
public bool IsRunning(Guid workflowDefinitionId)
{
bool isRunning;
var keyFound = _runningWorkflowDefinitions.TryGetValue(workflowDefinitionId, out isRunning);
return keyFound ? isRunning : IS_NOT_RUNNING_FLAG;
}
public void SetStatusToRunning(Guid workflowDefinitionId)
{
_runningWorkflowDefinitions.AddOrUpdate(workflowDefinitionId, IS_RUNNING_FLAG,
(definitionId, isRunning) => IS_RUNNING_FLAG);
}
public void SetStatusToNotRunning(Guid workflowDefinitionId)
{
_runningWorkflowDefinitions.AddOrUpdate(workflowDefinitionId.Value, IS_NOT_RUNNING_FLAG,
(definitionId, isRunning) => IS_NOT_RUNNING_FLAG);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment