-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to log job output to a file after the jobs are completed #173
Comments
ghost
changed the title
The WriteObject and WriteError methods cannot be called from outside the overrides of the BeginProcessing, ProcessRecord, and EndProcessing methods, and they can only be called from within the same thread. Validate that the cmdlet makes these calls correctly, or contact Microsoft Customer Support Services.
How to log job output to a file after the jobs are completed
Jan 10, 2018
any info about your environment ? |
Please run the script below, This needs a SQL Server instance. It is
intermittent though (may have to run multiple times). I am using Windows10
+ PSVersion 5.0.10586.1176 + 1.7.3.9(PoshRSJob)
*SCRIPT*
$serverName = "localhost"
$databaseName = “master"
1..31| Start-RSJob -Throttle 31 -Name {$_} -ScriptBlock {
Invoke-Sqlcmd -ServerInstance
$Using:serverName -Database $Using:databaseName -Query "select getdate()"
-OutputSqlErrors $true -QueryTimeout 65536 | out-null
[pscustomobject]@{
FileToProcess = $_
Server=$Using:serverName
Database=$Using:databaseName
Time = $(Get-Date)
}
} | Wait-RSJob -ShowProgress | Receive-RSJob
-WarningVariable wv -ErrorVariable er; $wv; $er
*OUTPUT*
The WriteObject and WriteError methods cannot be called from outside the
overrides of the BeginProcessing, ProcessRecord, and EndProcessing methods,
and they can only be called from within the
same thread. Validate that the cmdlet makes these calls correctly, or
contact Microsoft Customer Support Services.
The WriteObject and WriteError methods cannot be called from outside the
overrides of the BeginProcessing, ProcessRecord, and EndProcessing methods,
and they can only be called from within the
same thread. Validate that the cmdlet makes these calls correctly, or
contact Microsoft Customer Support Services.
FileToProcess Server Database Time
------------- ------ -------- ----
4 localhost master 1/10/2018 10:46:43 PM
10 localhost master 1/10/2018 10:46:44 PM
11 localhost master 1/10/2018 10:46:43 PM
13 localhost master 1/10/2018 10:46:43 PM
15 localhost master 1/10/2018 10:46:43 PM
16 localhost master 1/10/2018 10:46:44 PM
18 localhost master 1/10/2018 10:46:44 PM
20 localhost master 1/10/2018 10:46:44 PM
22 localhost master 1/10/2018 10:46:44 PM
23 localhost master 1/10/2018 10:46:44 PM
25 localhost master 1/10/2018 10:46:44 PM
26 localhost master 1/10/2018 10:46:45 PM
28 localhost master 1/10/2018 10:46:45 PM
29 localhost master 1/10/2018 10:46:45 PM
30 localhost master 1/10/2018 10:46:45 PM
31 localhost master 1/10/2018 10:46:45 PM
24 localhost master 1/10/2018 10:46:45 PM
21 localhost master 1/10/2018 10:46:46 PM
27 localhost master 1/10/2018 10:46:46 PM
19 localhost master 1/10/2018 10:46:46 PM
17 localhost master 1/10/2018 10:46:46 PM
14 localhost master 1/10/2018 10:46:46 PM
The pipeline has been stopped.
The WriteObject and WriteError methods cannot be called from outside the
overrides of the BeginProcessing, ProcessRecord, and EndProcessing methods,
and they can only be called from within the
same thread. Validate that the cmdlet makes these calls correctly, or
contact Microsoft Customer Support Services.
9 localhost master 1/10/2018 10:46:47 PM
The pipeline has been stopped.
12 localhost master 1/10/2018 10:46:47 PM
8 localhost master 1/10/2018 10:46:47 PM
7 localhost master 1/10/2018 10:46:47 PM
6 localhost master 1/10/2018 10:46:47 PM
5 localhost master 1/10/2018 10:46:47 PM
2 localhost master 1/10/2018 10:46:47 PM
1 localhost master 1/10/2018 10:46:48 PM
3 localhost master 1/10/2018 10:46:48 PM
Also how do I track exceptions for jobs for which HasErrors == true? How to
re-direct job errors to a file?
Id Name State HasMoreData HasErrors
Command
-- ---- ----- ----------- ---------
-------
2654 bcp_Orders_Partit... Completed False False ...
*2656 bcp_Orders_Partit... Completed False True
... *
*2662 bcp_Orders_Partit... Completed False True
... *
*2665 bcp_Orders_Partit... Completed False True
... *
*2666 bcp_Orders_Partit... Completed False True
... *
*2668 bcp_Orders_Partit... Completed False True
... *
*2669 bcp_Orders_Partit... Completed False True
... *
*2671 bcp_Orders_Partit... Completed False True
... *
*2673 bcp_Orders_Partit... Completed False True
... *
*2675 bcp_Orders_Partit... Completed False True
... *
*2677 bcp_Orders_Partit... Completed False True
... *
2678 bcp_Orders_Partit... Completed False False …
On January 10, 2018 at 2:30:08 PM, Max Kozlov ([email protected]) wrote:
any info about your environment ?
I can't reproduce this
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#173 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AP6v6dpjXYEuJkCECfVjfOkBDlWQSlBxks5tJQ--gaJpZM4RZZvp>
.
|
The error itself not in $serverName = "localhost"
$databaseName = "master"
1..31 | Start-RSJob -Throttle 31 -Name { $_ } -ScriptBlock {
$params = @{
ServerInstance = $Using:serverName
Database = $Using:databaseName
Query = "select getdate()"
OutputSqlErrors = $true
QueryTimeout = 65536
}
$err = $null
try {
Invoke-SqlCmd @params | Out-Null
}
catch {
$err = $_
}
[pscustomobject]@{
FileToProcess = $_
Server=$Using:serverName
Database=$Using:databaseName
Time = $(Get-Date)
Error = $err
}
} | Wait-RSJob -ShowProgress | Receive-RSJob -WarningVariable wv -ErrorVariable er
$wv
$er |
Thank you. Something funky with Invoke-Sqlcmd
On January 11, 2018 at 1:57:12 AM, Max Kozlov ([email protected]) wrote:
The error itself not in RSJob module
Seems there is something in Invoke-SqlCmd use direct output to $host, so it
is not thred safe
this code variant show that error catched inside Invoke-SQLCmd
$serverName = "localhost"$databaseName = "master"
1..31 | Start-RSJob -Throttle 31 -Name { $_ } -ScriptBlock {
$params = @{
ServerInstance = $Using:serverName
Database = $Using:databaseName
Query = "select getdate()"
OutputSqlErrors = $true
QueryTimeout = 65536
}
$err = $null
try {
Invoke-SqlCmd @params | Out-Null
}
catch {
$err = $_
}
[pscustomobject]@{
FileToProcess = $_
Server=$Using:serverName
Database=$Using:databaseName
Time = $(Get-Date)
Error = $err
}
} | Wait-RSJob -ShowProgress | Receive-RSJob -WarningVariable wv
-ErrorVariable er$wv$er
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#173 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AP6v6UcojtqmQ5Y9QCAZRoKhbg6BCwmNks5tJbDHgaJpZM4RZZvp>
.
|
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tried doing this
Get-RSJob | Receive-RSJob | Format-Table -AutoSize | Out-File $outfile
Got below error
The WriteObject and WriteError methods cannot be called from outside the overrides of the BeginProcessing, ProcessRecord, and EndProcessing methods, and they can only be called from within the same thread. Validate that the cmdlet makes these calls correctly, or contact Microsoft Customer Support Services.
I am calling the script containing Start-RSJob from another script using
Invoke-Expression { script file + params }
The text was updated successfully, but these errors were encountered: