The Llamachant Framework Workflow Service module provides a standalone engine for processing workflow definitions created by the Llamachant Framework Workflow module. It enables decoupled, scalable, and scheduled execution of workflows, ideal for background processing scenarios.
This module can be hosted in a variety of runtime environments, including:
The Llamachant Framework Workflow Service module provides a standalone engine for processing workflow definitions created by the Llamachant Framework Workflow module. It enables decoupled, scalable, and scheduled execution of workflows, ideal for background processing scenarios.
This module can be hosted in a variety of runtime environments, including:
Install-Package 'LlamachantFramework.Workflow.Service'
Install-Package 'LlamachantFramework.Workflow.Service'
Once the module is installed, follow these steps:
WorkflowService.Instance[FunctionName("RunWorkflowFunction")]
public void Run([TimerTrigger("0 * * * * *")] TimerInfo myTimer, ILogger log, ExecutionContext context)
{
DevExpress.Utils.AzureCompatibility.Enable = true;
try
{
log.LogInformation("*** Function is starting ***");
if (app == null)
{
config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
#if DEBUG
.AddJsonFile("local.settings.json", optional: true)
#endif
.AddEnvironmentVariables()
.Build();
IHostBuilder hostBuilder = Program.CreateHostBuilder(new string[0]);
app = (MyBlazorApplication)DesignTimeApplicationFactoryHelper.Create(hostBuilder);
app.ConnectionString = config.GetConnectionString("ConnectionString");
app.Setup();
log.LogInformation("Application created and setup complete.");
}
WorkflowService.Instance.TimeZone = TimeZoneInfo.FindSystemTimeZoneById(config.GetValue<string>("WorkflowTimezone"));
if (!app.GetSecurityStrategy().IsAuthenticated)
{
var p = new AuthenticationStandardLogonParameters {
UserName = config.GetValue<string>("WorkflowUserName"),
Password = config.GetValue<string>("WorkflowPassword")
};
app.GetSecurityStrategy().Logon(p);
}
if (app.GetSecurityStrategy().IsAuthenticated)
{
WorkflowService.Instance.Initialize(app, log);
WorkflowService.Instance.RunWorkflow();
}
log.LogInformation("*** Function is ending ***");
}
catch (Exception ex)
{
log.LogError(ex, "******** Service Crash ********");
}
}
public partial class MyWorkflowService : ServiceBase
{
WorkflowQueueController queue = new WorkflowQueueController();
public MyWorkflowService() => InitializeComponent();
protected override void OnStart(string[] args)
{
queue.SetInterval(60);
queue.Start();
}
protected override void OnStop() => queue.Stop();
}
public class MyConsoleApp
{
public static void Main(string[] args)
{
var app = new MyWindowsFormsApplication();
app.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
app.Setup();
var p = new AuthenticationStandardLogonParameters { UserName = "Admin" };
app.GetSecurityStrategy().Logon(p);
WorkflowService.Instance.Initialize(app, new FileSystemLogger(@"C:\Logs\"));
WorkflowService.Instance.RunWorkflow();
}
}
WorkflowService.Instance.ProgressWorkflowDefinitionDate += (s, args) =>
{
while (e.NextRunDate.DayOfWeek == DayOfWeek.Saturday || e.NextRunDate.DayOfWeek == DayOfWeek.Sunday)
e.NextRunDate = e.NextRunDate.AddDays(1);
};
WorkflowService.Instance.CalculateNeedsProcessing += (s, args) =>
{
var c = e.ObjectToProcess as Client;
bool blankemail = c != null && string.IsNullOrEmpty(c.EmailAddress) && e.WorkflowDefinition.Name == "My workflow Definition";
e.Process = !blankemail;
};
Once the module is installed, follow these steps:
WorkflowService.Instance[FunctionName("RunWorkflowFunction")]
public void Run([TimerTrigger("0 * * * * *")] TimerInfo myTimer, ILogger log, ExecutionContext context)
{
DevExpress.Utils.AzureCompatibility.Enable = true;
try
{
log.LogInformation("*** Function is starting ***");
if (app == null)
{
config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
#if DEBUG
.AddJsonFile("local.settings.json", optional: true)
#endif
.AddEnvironmentVariables()
.Build();
IHostBuilder hostBuilder = Program.CreateHostBuilder(new string[0]);
app = (MyBlazorApplication)DesignTimeApplicationFactoryHelper.Create(hostBuilder);
app.ConnectionString = config.GetConnectionString("ConnectionString");
app.Setup();
log.LogInformation("Application created and setup complete.");
}
WorkflowService.Instance.TimeZone = TimeZoneInfo.FindSystemTimeZoneById(config.GetValue<string>("WorkflowTimezone"));
if (!app.GetSecurityStrategy().IsAuthenticated)
{
var p = new AuthenticationStandardLogonParameters {
UserName = config.GetValue<string>("WorkflowUserName"),
Password = config.GetValue<string>("WorkflowPassword")
};
app.GetSecurityStrategy().Logon(p);
}
if (app.GetSecurityStrategy().IsAuthenticated)
{
WorkflowService.Instance.Initialize(app, log);
WorkflowService.Instance.RunWorkflow();
}
log.LogInformation("*** Function is ending ***");
}
catch (Exception ex)
{
log.LogError(ex, "******** Service Crash ********");
}
}
public partial class MyWorkflowService : ServiceBase
{
WorkflowQueueController queue = new WorkflowQueueController();
public MyWorkflowService() => InitializeComponent();
protected override void OnStart(string[] args)
{
queue.SetInterval(60);
queue.Start();
}
protected override void OnStop() => queue.Stop();
}
public class MyConsoleApp
{
public static void Main(string[] args)
{
var app = new MyWindowsFormsApplication();
app.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
app.Setup();
var p = new AuthenticationStandardLogonParameters { UserName = "Admin" };
app.GetSecurityStrategy().Logon(p);
WorkflowService.Instance.Initialize(app, new FileSystemLogger(@"C:\Logs\"));
WorkflowService.Instance.RunWorkflow();
}
}
WorkflowService.Instance.ProgressWorkflowDefinitionDate += (s, args) =>
{
while (e.NextRunDate.DayOfWeek == DayOfWeek.Saturday || e.NextRunDate.DayOfWeek == DayOfWeek.Sunday)
e.NextRunDate = e.NextRunDate.AddDays(1);
};
WorkflowService.Instance.CalculateNeedsProcessing += (s, args) =>
{
var c = e.ObjectToProcess as Client;
bool blankemail = c != null && string.IsNullOrEmpty(c.EmailAddress) && e.WorkflowDefinition.Name == "My workflow Definition";
e.Process = !blankemail;
};