Sample code to enable PollTasksOnJobCompletion on sequential task queue

Hi,

Has anyone ever really used this property to enable the PollTasksOnJobCompletion for the task like below?

https://developer.m-files.com/Frameworks/Vault-Application-Framework/Reference/html/7c0ba55f-0b28-3677-392a-b0f704aa8222.htm

I want the queue to run faster because it processes around 40 tasks per min, the total running time is 20 seconds, that means there are 40 seconds just pulsed for the next polling. I believed i can enable it to immediately kick off the next task, BTW, I have included the name space of Multiserver but this is an on-premise server so not really using multiple servers.

[TaskQueue(Behavior = MFTaskQueueProcessingBehavior.MFProcessingBehaviorSequential )]
public const string ExecuteCommandQueueId = "ExecuteCommandQueue";
public const string ExecuteCommandTaskType = "ExecuteCommandQueue";

Thanks

Bin

  • I found some sample code like below:

     

    public class VaultApplication
    	: MFiles.VAF.Core.ConfigurableVaultApplicationBase<Configuration>, IUsesTaskQueue
    {
    	/// <summary>
    	/// The token source for task processing cancellation.
    	/// </summary>
    	private CancellationTokenSource TokenSource { get; set; }
    
    	/// <summary>
    	/// The task queue ID. This should be unique for your application
    	/// so that you don't interfere with other task queues.
    	/// </summary>
    	public const string BackgroundOperationTaskQueueId = "MFiles.Samples.RecurringBackgroundOperation.Application.TaskQueueId";
    
    	/// <summary>
    	/// The concurrent task processor.
    	/// </summary>
    	public AppTaskBatchProcessor TaskProcessor { get; set; }
    
    	/// <summary>
    	/// The task type.
    	/// This can be used to have different handlers for different types of task in your queue.
    	/// </summary>
    	public const string TaskTypeHourlyRecurringTask = "TaskType.HourlyRecurringTask";
    
    	/// <summary>
    	/// Override the start operations so we can register our task processor.
    	/// </summary>
    	/// <param name="vaultPersistent">Non-transactional Vault object.</param>
    	public override void StartOperations(Vault vaultPersistent)
    	{
    		// Allow the base to process the start operations.
    		base.StartOperations(vaultPersistent);
    
    		// Enable polling/processing of the queue.
    		this.TaskQueueManager.EnableTaskPolling(true);
    	}
    
    	/// <summary>
    	/// Registers the task queue used by this application or module.
    	/// </summary>
    	public void RegisterTaskQueues()
    	{
    		// Create the cancellation token source.
    		if (this.TokenSource == null)
    			this.TokenSource = new CancellationTokenSource();
    
    		// Create the task processor.
    		if (this.TaskProcessor == null)
    		{
    			// Initialize the task processor.
    			this.TaskProcessor = new AppTaskBatchProcessor
    			(
    				new AppTaskBatchProcessorSettings
    				{
    					QueueDef = new TaskQueueDef
    					{
    						TaskType = TaskQueueManager.TaskType.Both,
    						Id = VaultApplication.BackgroundOperationTaskQueueId,
    						ProcessingBehavior = MFTaskQueueProcessingBehavior.MFProcessingBehaviorConcurrent,
    						MaximumPollingIntervalInSeconds = this.Configuration.MaxPollingIntervalInSeconds,
    						LastBroadcastId = ""
    					},
    					PermanentVault = this.PermanentVault,
    					MaxConcurrentBatches = this.Configuration.MaxConcurrentBatches,
    					MaxConcurrentJobs = this.Configuration.MaxConcurrentJobs,
    					TaskHandlers = new Dictionary<string, TaskProcessorJobHandler>
    					{
    						{ VaultApplication.TaskTypeHourlyRecurringTask, ProcessHourlyTask }
    					},
    					TaskQueueManager = this.TaskQueueManager,
    					EnableAutomaticTaskUpdates = true,
    					DisableAutomaticProgressUpdates = false,
    					PollTasksOnJobCompletion = true
    				},
    				this.TokenSource.Token
    			);
    
    			// Schedule the hourly task.
    			ScheduleHourlyTask();
    
    		}
    
    		// Register the task queue.
    		this.TaskProcessor.RegisterTaskQueues();
    
    		// Ensure that the configuration broadcast queue is initialized.
    		this.InitializeConfigurationBroadcastProcessor();
    	}

    But my code was using the  MFiles.VAF.Extensions.ConfigurableVaultApplicationBase<Configuration> because it came with configuration and logging helpers. It seems to make the "AppTaskProcessorSettings" not editable.

     

    public class VaultApplication
    	: MFiles.VAF.Extension.ConfigurableVaultApplicationBase<Configuration>, IUsesTaskQueue