Skip to content

runnable pollers splitting #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/WorkflowCore.Testing/WorkflowTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected void Host_OnStepError(WorkflowInstance workflow, WorkflowStep step, Ex

protected virtual void ConfigureServices(IServiceCollection services)
{
services.AddWorkflow(options => options.UsePollInterval(TimeSpan.FromSeconds(3)));
services.AddWorkflow(options => options.UsePollWorkflowsInterval(TimeSpan.FromSeconds(3)));
}

public string StartWorkflow(TData data)
Expand Down
22 changes: 18 additions & 4 deletions src/WorkflowCore/Models/WorkflowOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public class WorkflowOptions
internal Func<IServiceProvider, IDistributedLockProvider> LockFactory;
internal Func<IServiceProvider, ILifeCycleEventHub> EventHubFactory;
internal Func<IServiceProvider, ISearchIndex> SearchIndexFactory;
internal TimeSpan PollInterval;
internal TimeSpan PollWorkflowsInterval;
internal TimeSpan PollEventsInterval;
internal TimeSpan PollCommandsInterval;
internal TimeSpan IdleTime;
internal TimeSpan ErrorRetryInterval;
internal int MaxConcurrentWorkflows = Math.Max(Environment.ProcessorCount, 4);
Expand All @@ -23,7 +25,9 @@ public class WorkflowOptions
public WorkflowOptions(IServiceCollection services)
{
Services = services;
PollInterval = TimeSpan.FromSeconds(10);
PollWorkflowsInterval = TimeSpan.FromSeconds(10);
PollEventsInterval = TimeSpan.FromSeconds(10);
PollCommandsInterval = TimeSpan.FromSeconds(10);
IdleTime = TimeSpan.FromMilliseconds(100);
ErrorRetryInterval = TimeSpan.FromSeconds(60);

Expand Down Expand Up @@ -65,9 +69,19 @@ public void UseSearchIndex(Func<IServiceProvider, ISearchIndex> factory)
SearchIndexFactory = factory;
}

public void UsePollInterval(TimeSpan interval)
public void UsePollWorkflowsInterval(TimeSpan interval)
{
PollInterval = interval;
PollWorkflowsInterval = interval;
}

public void UsePollEventsInterval(TimeSpan interval)
{
PollEventsInterval = interval;
}

public void UsePollCommandsInterval(TimeSpan interval)
{
PollCommandsInterval = interval;
}

public void UseErrorRetryInterval(TimeSpan interval)
Expand Down
5 changes: 4 additions & 1 deletion src/WorkflowCore/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using WorkflowCore.Primitives;
using WorkflowCore.Services.BackgroundTasks;
using WorkflowCore.Services.ErrorHandlers;
using WorkflowCore.Services.BackgroundTasks.RunnablePoller;

namespace Microsoft.Extensions.DependencyInjection
{
Expand Down Expand Up @@ -50,7 +51,9 @@ public static IServiceCollection AddWorkflow(this IServiceCollection services, A

if (options.EnablePolling)
{
services.AddTransient<IBackgroundTask, RunnablePoller>();
services.AddTransient<IBackgroundTask, WorkflowRunnablePoller>();
services.AddTransient<IBackgroundTask, EventRunnablePoller>();
services.AddTransient<IBackgroundTask, CommandRunnablePoller>();
}

services.AddTransient<IBackgroundTask>(sp => sp.GetService<ILifeCycleEventPublisher>());
Expand Down
221 changes: 0 additions & 221 deletions src/WorkflowCore/Services/BackgroundTasks/RunnablePoller.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Threading;
using WorkflowCore.Interface;

namespace WorkflowCore.Services.BackgroundTasks.RunnablePoller
{
internal abstract class BaseWorkflowRunnablePoller : IBackgroundTask
{
private readonly TimeSpan _pollInterval;
private Timer _pollTimer;

protected BaseWorkflowRunnablePoller(TimeSpan pollInterval)
{
_pollInterval = pollInterval;
}

public void Start()
{
_pollTimer = new Timer(new TimerCallback(PollRunnables), null, TimeSpan.FromSeconds(0), _pollInterval);
}

public void Stop()
{
if (_pollTimer != null)
{
_pollTimer.Dispose();
_pollTimer = null;
}
}


protected abstract void PollRunnables(object target);
}
}
Loading