can I test if a consolidation is already running before running a new one ?

Stan
New Contributor II

Is it possible to test if a consolidation or a data management job is already running before running it again ?

Ex: I run a consolidation (about 10min) but another people run the same consolidation the same time

Thank you for your help

3 REPLIES 3

Henning
Contributor III

Hi Stan, unfortunately, I do not have time to test this or write the code at the moment, but you should be able to access the task activity, filter the Task Activity for the DM job you want to run and check the Task Status column for <> Completed / Failed / etc. And when one is running, you can return a message to the user.

Henning_0-1669818575207.png

Please note that this very much depends on your process. In your example (=DM job), you can just run a BR as the first step of the DM sequence to check. In reality, I never implemented this but rather educated the users not to blindly click "consolidate" all the time but rather check the consolidation status of their entity. Also, setting up the workflow and general process in a way that there is no need to consolidate all the time is another complementary setup.

Here is q quick dashboard extender rule example that executes a logic only when no consolidation is running. Please note that in the SQL code I limited the check to the top 10 Task Activity Types. Please adjust  this as well as the rest of the exemplary code in accordance with your requirements. Also, this is not an event handler or listener. This typically executes from a dashboard button.

 

One can find task activity types in this post:

https://community.onestreamsoftware.com/t5/Application-Build/Task-Activity-Type/m-p/8311

 

Imports System.Collections.Generic
Imports System.Data
Imports System.Data.Common
Imports System.Globalization
Imports System.IO
Imports System.Linq
Imports System.Windows.Forms
Imports Microsoft.VisualBasic
Imports OneStream.Finance.Database
Imports OneStream.Finance.Engine
Imports OneStream.Shared.Common
Imports OneStream.Shared.Database
Imports OneStream.Shared.Engine
Imports OneStream.Shared.Wcf
Imports OneStream.Stage.Database
Imports OneStream.Stage.Engine

Namespace OneStream.BusinessRule.DashboardExtender.TA_DashboardHelperQueries
	Public Class MainClass
		Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As DashboardExtenderArgs) As Object
			Try
				Select Case args.FunctionType
										
					Case Is = DashboardExtenderFunctionType.ComponentSelectionChanged
						If args.FunctionName.XFEqualsIgnoreCase("CheckTaskActivity") Then
							
							'Retrieve parameters passed to rule, possibly to be used to filter the current data unit, if needed
							Dim wfTimeParameter As String = args.NameValuePairs.XFGetValue("wfTimeParameter")
							Dim wfScenarioParameter As String = args.NameValuePairs.XFGetValue("wfScenarioParameter")
							Dim wfProfileParameter As String = args.NameValuePairs.XFGetValue("WFProfileParameter")
							Dim wfAppNameParameter As String = args.NameValuePairs.XFGetValue("wfAppNameParameter")
							
							'Define string to write to error log for further analysis of running / blocking tasks
							Dim errorLogMessage As New List(Of String)
							errorLogMessage.Add("The below tasks are running. Please wait for those to complete before executing your routine.")
							
							'Define SQL script to pull necessary information from TaskActivity table
							Dim sql As New Text.StringBuilder
							sql.AppendLine("SELECT top 10 TaskActivityType, 'Unknown' as TaskActivityTypeDesc, TaskActivityStatus, 'Unknown' as TaskActivityStatusDesc, Description, AppName, UserName ")
							sql.AppendLine("FROM [OneStream_Framework].dbo.[TaskActivity] ")
							
							'Pull rows from table for required task types and status
								'TaskActivityType 9000 = Calculate, 11000 = Consolidate
								'TaskActivityStatus 0 = Queued, 1000 = Running
							sql.AppendLine($"WHERE TaskActivityType = '11000' AND TaskActivityStatus = '1000' AND AppName = '{wfAppNameParameter}'")
							 

							'Using SQL syntax and ExecuteSqlUsingReader to get the Data Table
			                Dim dt As DataTable = Nothing
			                Using dbConnApp As DbConnInfo = BRApi.Database.CreateApplicationDbConnInfo(si)
			                    dt = BRApi.Database.ExecuteSqlUsingReader(dbConnApp, sql.ToString, False)
							End Using	
							
							Dim selectionChangedTaskResult As New XFSelectionChangedTaskResult()
							selectionChangedTaskResult.IsOK = True
							selectionChangedTaskResult.ShowMessageBox = True
							selectionChangedTaskResult.ChangeSelectionChangedUIActionInDashboard = False
							selectionChangedTaskResult.ModifiedSelectionChangedUIActionInfo = Nothing
							selectionChangedTaskResult.ChangeSelectionChangedNavigationInDashboard = False
							selectionChangedTaskResult.ModifiedSelectionChangedNavigationInfo = Nothing
							selectionChangedTaskResult.ChangeCustomSubstVarsInDashboard = False
							selectionChangedTaskResult.ModifiedCustomSubstVars = Nothing
							selectionChangedTaskResult.ChangeCustomSubstVarsInLaunchedDashboard = False
							selectionChangedTaskResult.ModifiedCustomSubstVarsForLaunchedDashboard = Nothing
						
							'Check if determined activity types are running and create message
'							If Not dt Is Nothing Then
							If Not dt.Rows.Count.XFToString.XFContainsIgnoreCase("0") Then
								selectionChangedTaskResult.Message = "Task is running, please check the task activity and wait for it to be completed."
								
								dt.Columns("TaskActivityTypeDesc").ReadOnly = False
								dt.Columns("TaskActivityTypeDesc").MaxLength = -1
								dt.Columns("TaskActivityStatusDesc").ReadOnly = False
								dt.Columns("TaskActivityStatusDesc").MaxLength = -1

								For Each dr As DataRow In dt.Rows

									dr.BeginEdit
										dr("TaskActivityTypeDesc") = TaskActivityType.GetName(GetType(TaskActivityType), dr("TaskActivityType"))
										dr("TaskActivityStatusDesc") = TaskActivityStatus.GetName(GetType(TaskActivityStatus), dr("TaskActivityStatus"))
									dr.EndEdit
									
									errorLogMessage.Add("Process: " & dr("TaskActivityTypeDesc").ToString & " - Status: " & dr("TaskActivityStatusDesc").ToString & " - Data Unit: " & dr("Description").ToString & " - User: " & dr("UserName").ToString)
								Next
								
								'Write running tasks into error log							
								brapi.ErrorLog.LogMessage(si,"Running Tasks: See details below.", vbCrLf & String.Join(vbCrLf, errorLogMessage.ToArray))
								
							Else
								selectionChangedTaskResult.Message = "Task successfully completed."
								'...run DM job or whatever is needed when no other process is blocking
								'...execute logic from here!
								
							End If
														
							Return selectionChangedTaskResult
							
						End If
					
				End Select

				Return Nothing
			Catch ex As Exception
				Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
			End Try
		End Function
	End Class
End Namespace

 

Sweez
New Contributor III

You can use a wcfEventHandler to listen for a consolidaton and pick up the data unit info. You could then query the TaskActivity framework table to see what is running and return an error if needed. The SQL would look somethign like this:

Select Description, UserName, AppName, StartTime, PercentComplete

From TaskActivity Where taskactivitytype = 11000 and appname = 'GolfStream' and taskactivitystatus = 1000

The descirption field will have the data unit info to compare to the requested consolidation.