Skip to content
Merged
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 tasks/start_sql_agent_job.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"job_name": {
"description": "The name of the job to start.",
"type": "Optional[Variant[Array[String],String]]"
"type": "Variant[Array[String],String]"
},
"fuzzy_match": {
"description": "Turn the job_name parameter into a pattern to match using the PowerShell -match operator.",
Expand Down
22 changes: 4 additions & 18 deletions tasks/start_sql_agent_job.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,8 @@ foreach ($instance in $SQLInstances) {
}

foreach ($currentJob in $sqlserver.jobserver.jobs) {
if ($MyInvocation.BoundParameters.ContainsKey('job_name')) {
if ($selectedJob = (Select-JobStrict -job $currentJob -jobsToMatch $job_name -fuzzy_match:$fuzzy_match)) {
[void]$jobs.add($selectedJob)
$jobName = $selectedJob.jobsteps[$step].name
if([string]::IsNullOrEmpty($jobName)){
$message = `
("No job step found at index {0}. There are {1} steps in the job `"{2}`". Remember that these are zero based array indexes." `
-f $step, $selectedJob.jobSteps.count, $selectedJob.name)
return (Write-BoltError $message)
}
$selectedJob.start($jobName)
# It takes the server a little time to spin up the job. If we don't do this here
# then the -wait parameter may not work later.
Start-Sleep -Milliseconds 300
}
}
else {
[void]$jobs.add($currentJob)
if ($selectedJob = (Select-JobStrict -job $currentJob -jobsToMatch $job_name -fuzzy_match:$fuzzy_match)) {
[void]$jobs.add($selectedJob)
$jobName = $selectedJob.jobsteps[$step].name
if([string]::IsNullOrEmpty($jobName)){
$message = `
Expand All @@ -95,6 +79,8 @@ foreach ($instance in $SQLInstances) {
return (Write-BoltError $message)
}
$selectedJob.start($jobName)
# It takes the server a little time to spin up the job. If we don't do this here
# then the -wait parameter may not work later.
Start-Sleep -Milliseconds 300
}
}
Expand Down