-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more functionality for joblog in #13
- Loading branch information
Showing
5 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
AptecoPSFramework/private/hashtable/ConvertFrom-JsonAsHashtable.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Function ConvertFrom-JsonAsHashtable { | ||
|
||
# To solve these problems, load the content with Invoke-WebRequest rather than Invoke-RestMethod, and convert the content with the function above | ||
|
||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory = $true, | ||
Position = 0, | ||
ValueFromPipeline = $true)] | ||
[AllowEmptyString()] | ||
[String] $InputObject | ||
) | ||
DynamicParam { | ||
# All parameters, except Uri and body (needed as an object) | ||
$p = Get-BaseParameters "ConvertFrom-Json" | ||
[void]$p.remove("InputObject") | ||
$p | ||
} | ||
|
||
Begin { | ||
$jsSerializer = [System.Web.Script.Serialization.JavaScriptSerializer]::new() | ||
} | ||
|
||
Process { | ||
|
||
Write-Verbose $InputObject | ||
$jsSerializer.Deserialize($InputObject, 'Hashtable') | ||
|
||
} | ||
|
||
end { | ||
$jsSerializer = $null | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
Function Get-JobLog { | ||
<# | ||
... | ||
# TODO maybe allow to show all jobs or since a specific job or something | ||
#> | ||
[cmdletbinding()] | ||
param( | ||
[Parameter(Mandatory=$true)][Int]$JobId | ||
,[Parameter(Mandatory=$false)][Switch]$ConvertInputAsHashtable = $false | ||
#,[Parameter(Mandatory=$true)][String]$ConnectionString | ||
# TODO also allow use other connection strings as input parameter? | ||
) | ||
|
||
Process { | ||
|
||
# TODO check if connection is open? | ||
|
||
$job = Read-DuckDBQueryAsReader -Name "JobLog" -Query "SELECT * FROM joblog WHERE id = $( $JobId )" -ReturnAsPSCustom | ||
|
||
If ( $job.count -eq 0 ) { | ||
throw "No job found with id $( $JobId )" | ||
} elseif ( $job.count -gt 1 ) { | ||
throw "Multiple jobs found with id $( $JobId )" | ||
} else { | ||
|
||
If ( $ConvertInputAsHashtable -eq $true) { | ||
$job.input = ConvertFrom-JsonAsHashtable $job.input | ||
} | ||
|
||
# return | ||
$job | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters