Skip to content

Commit

Permalink
Added more functionality for joblog in #13
Browse files Browse the repository at this point in the history
  • Loading branch information
gitfvb committed Jul 4, 2024
1 parent d5cafc3 commit 4da3162
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 2 deletions.
2 changes: 1 addition & 1 deletion AptecoPSFramework/bin/dependencies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ $psLocalPackages = [Array]@(
)

$psAssemblies = [Array]@(

"System.Web.Extensions" # Needed for deserialisation of ConvertFrom-Json
)
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
}

}
39 changes: 39 additions & 0 deletions AptecoPSFramework/private/jobs/Get-JobLog.ps1
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
}

}

}
1 change: 0 additions & 1 deletion AptecoPSFramework/private/jobs/Set-JobLogDatabase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Function Set-JobLogDatabase {
$joblogCreateStatement = Get-Content -Path $joblogCreateStatementPath -Encoding UTF8 -Raw
Invoke-DuckDBQueryAsNonExecute -Query $joblogCreateStatement -ConnectionName "JobLog"


}

}
1 change: 1 addition & 0 deletions AptecoPSFramework/sql/joblog_create.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-- sqlite
CREATE TABLE IF NOT EXISTS joblog (
id INTEGER PRIMARY KEY
,created TEXT DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW', 'localtime'))
Expand Down

0 comments on commit 4da3162

Please sign in to comment.