dbatools icon indicating copy to clipboard operation
dbatools copied to clipboard

Add -Wait parameter to Start-DbaAgentJob

Open lanlanzeliu opened this issue 8 years ago • 10 comments


name: Add -Wait parameter to Start-DbaAgentJob :bomb: about: I would like to see Start-DbaAgentJob support a -Wait parameter so that it waits for the job to finish before returning context to the user/program


Summary of new feature

  • I would like Start-DbaAgentJob to support a -Wait parameter so that it waits for the job to finish before returning context to the user/program.

Proposed technical details (if applicable)

  • It would be nice if this included the status of the job that completed, or produces an error if the job does not succeed.
  • It would also be nice to be able to include a second, optional parameter, to specify how often the loop checks for whether the job has completed. If you expect a job to run in ~5 minutes, maybe 2-5 seconds is fine, but if you expect a job to run for 2-3 hours, maybe a check every 5 minutes is sufficient.

Latest version of dbatools as of writing

  • 0.9.450

lanlanzeliu avatar Oct 01 '18 20:10 lanlanzeliu

@niphlod Here is the issue we spoke about in DbaTools Slack. Thanks for considering.

Adam-Wenger avatar Oct 01 '18 20:10 Adam-Wenger

I think the second problem can be solved waiting exponentially till 5 minutes, which is a sane default that leaves more "needy users" in resolving their "problem" with 3 additional lines . With -Wait there's also -Timeout to be considered, at least watching from other examples in PS world. The more "urgent" is design-wise what to do with the status and/or the error. @wsmelton any ideas ?

niphlod avatar Oct 01 '18 21:10 niphlod

what if Wait was an int that defaulted to 0, you can use Test-Bound to determine if it was specified I believe

potatoqualitee avatar Oct 01 '18 21:10 potatoqualitee

just for the sake of keeping consistency in PSworld, isn't -Wait usually a switch ? -Wait 600 for "wait at most 600 secs" isn't something I've seen elsewhere

niphlod avatar Oct 01 '18 21:10 niphlod

Yes, it's usuaally a switch. when seconds are added in, it's usually WaitFor, I believe

potatoqualitee avatar Oct 01 '18 21:10 potatoqualitee

There is not native support for this in SQL Agent but requires polling to test job status. In my environment we implement a stored procedure to do this. One thing I noted is that need at least 15 seconds wait time to avoid weird false positives.

sqllensman avatar Oct 02 '18 00:10 sqllensman

haha, ya'll gotta be kidding me ! there's already all the required features !

niphlod avatar Oct 02 '18 06:10 niphlod

/facepalm - Thanks @niphlod, sorry for wasting your time.

Adam-Wenger avatar Oct 02 '18 14:10 Adam-Wenger

LOL whoops, I didn't even remember that and the history suggests i added it 😆

potatoqualitee avatar Oct 02 '18 14:10 potatoqualitee

if only all feature request could go like this one 💃 . closing!

niphlod avatar Oct 02 '18 15:10 niphlod