Skip to content

Commit

Permalink
sdo that it formats adn that the configvalue is more performant #887
Browse files Browse the repository at this point in the history
  • Loading branch information
SQLDBAWithABeard committed Aug 23, 2023
1 parent 069750e commit 2ad34b2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions source/internal/functions/Get-AllAgentInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ function Get-AllAgentInfo {
}
}
'LastJobRunTime' {
$maxdays = Get-DbcConfigValue agent.failedjob.since
$maxdays = ($__dbcconfig | Where-Object { $_.Name -eq 'agent.failedjob.since' }).Value
$query = "IF OBJECT_ID('tempdb..#dbachecksLastRunTime') IS NOT NULL DROP Table #dbachecksLastRunTime
SELECT * INTO #dbachecksLastRunTime
FROM
Expand All @@ -335,7 +335,7 @@ function Get-AllAgentInfo {
msdb.dbo.sysjobhistory AS jh
ON jh.job_id = h.job_id
AND jh.instance_id = h.instance_id
WHERE msdb.dbo.agent_datetime(jh.run_date, jh.run_time) > DATEADD(DAY,- $maxdays,GETDATE())
WHERE msdb.dbo.agent_datetime(jh.run_date, jh.run_time) > DATEADD(DAY,- {0},GETDATE())
AND jh.step_id = 0
) AS lrt
IF OBJECT_ID('tempdb..#dbachecksAverageRunTime') IS NOT NULL DROP Table #dbachecksAverageRunTime
Expand All @@ -346,7 +346,7 @@ function Get-AllAgentInfo {
job_id,
AVG(DATEDIFF(SECOND, 0, STUFF(STUFF(RIGHT('000000' + CONVERT(VARCHAR(6),run_duration),6),5,0,':'),3,0,':'))) AS AvgSec
FROM msdb.dbo.sysjobhistory hist
WHERE msdb.dbo.agent_datetime(run_date, run_time) > DATEADD(DAY,- $maxdays,GETDATE())
WHERE msdb.dbo.agent_datetime(run_date, run_time) > DATEADD(DAY,- {0},GETDATE())
AND Step_id = 0
AND run_duration >= 0
GROUP BY job_id
Expand All @@ -360,7 +360,7 @@ function Get-AllAgentInfo {
JOIN #dbachecksAverageRunTime avgrun
ON lastrun.job_id = avgrun.job_id
DROP Table #dbachecksLastRunTime
DROP Table #dbachecksAverageRunTime"
DROP Table #dbachecksAverageRunTime" -f $maxdays
$lastagentjobruns = Invoke-DbaQuery -SqlInstance $Instance -Database msdb -Query $query

$ConfigValues | Add-Member -MemberType NoteProperty -Name 'LastJobRuns' -Value (Get-DbcConfigValue agent.lastjobruntime.percentage)
Expand Down

0 comments on commit 2ad34b2

Please sign in to comment.