You are on page 1of 1

Set-StrictMode -Version Latest

$connectionString = 'Driver={PostgreSQL ANSI(x64)};Server=????; Port=8060;


Database=workgroup; Uid=????; Pwd=????;'
$query = @"
select
*
from
(
SELECT
id,
created_at,
started_at,
completed_at,
finish_code,
job_type,
notes,
job_name,
title,
subtitle,
rank() over(partition by title order by started_at desc) as rnk
FROM _background_tasks
where title like '????'
) x
where x.rnk = 1
"@

$extractName = Get-TableauExtract -connectionString $connectionString -query


$query | Select-Object -ea 0 -ExpandProperty title
$extractCode = Get-TableauExtract -connectionString $connectionString -query
$query | Select-Object -ea 0 -ExpandProperty finish_code

:green Do {
#looking for a specific indicator (extract completed)
$TabResult = Get-TableauExtract -connectionString $connectionString -query
$query | Select-Object -ea 0 -ExpandProperty completed_at
if ( $TabResult -notlike $null) {
$extractNotes = Get-TableauExtract -connectionString $connectionString
-query $query | Select-Object -ea 0 -ExpandProperty notes
Send-MailMessage -To "????" -From "????" -Subject "Your $extractName is
complete with code of $extractCode" -Body "Extract Notes: $extractNotes"
-SmtpServer "????"
$keepgoing = $false
break green
} else {
$curTime = (Get-Date).DateTime
Write-Warning "Extract still refreshing as of: $curTime" 3>>
TabExtractDataLoading.txt
$keepgoing = $true
}
Start-Sleep -Seconds 1800 #check every 30 minutes if it's not done.
}While ( $keepgoing )

# if it's true, it continues. if it's false, it does not continue

You might also like