Skip to content

Commit

Permalink
Adding functionality to return also an arraylist rather than only has…
Browse files Browse the repository at this point in the history
…htable for #13
  • Loading branch information
gitfvb committed Jul 12, 2024
1 parent e067f77 commit d5c14c0
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 28 deletions.
2 changes: 1 addition & 1 deletion AptecoPSFramework/boilerplate/upload.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ try {

# return
If ( $useJob -eq $true ) {
$jobReturn = Get-JobLog -JobId $jobId -ConvertOutputAsHashtable
$jobReturn = Get-JobLog -JobId $jobId -ConvertOutput
$return = $jobReturn.output
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function Invoke-Upload{
"Job" {

# Get the jobs information
$job = Get-JobLog -JobId $JobId -ConvertInputAsHashtable
$job = Get-JobLog -JobId $JobId -ConvertInput
$InputHashtable = $job.input

# Update the job with more information
Expand Down Expand Up @@ -569,7 +569,7 @@ function Invoke-Upload{
"OutputParam" = $return
}
Update-JobLog @jobReturnParams
Close-DuckDBConnection -Name "JobLog"
Close-JobLogDatabase -Name "JobLog"

# return the results
Switch ( $PSCmdlet.ParameterSetName ) {
Expand Down
66 changes: 56 additions & 10 deletions AptecoPSFramework/public/jobs/Get-JobLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Function Get-JobLog {
[Parameter(Mandatory=$true, ParameterSetName = 'Single')][Int]$JobId

,[Parameter(Mandatory=$false, ParameterSetName = 'Single')]
[Switch]$ConvertInputAsHashtable = $false
[Switch]$ConvertInput = $false

,[Parameter(Mandatory=$false, ParameterSetName = 'Single')]
[Switch]$ConvertOutputAsHashtable = $false
[Switch]$ConvertOutput = $false

#,[Parameter(Mandatory=$true)][String]$ConnectionString

Expand All @@ -35,12 +35,31 @@ Function Get-JobLog {
throw "Multiple jobs found with id $( $JobId )"
} else {

If ( $ConvertInputAsHashtable -eq $true) {
If ( $ConvertInput -eq $true) {
$job.input = ConvertFrom-JsonAsHashtable $job.input
}

If ( $ConvertOutputAsHashtable -eq $true) {
$job.output = ConvertFrom-JsonAsHashtable $job.output
If ( $ConvertOutput -eq $true) {
Switch ( $job.returnformat ) {

# "ARRAY" {
# ConvertFrom-Json $job.output
# break
# }

"HASHTABLE" {
$job.output = ConvertFrom-JsonAsHashtable $job.output
break

}

default {
ConvertFrom-Json $job.output
break
}

}

}

}
Expand All @@ -60,10 +79,37 @@ Function Get-JobLog {
#$job = Read-DuckDBQueryAsReader -Name "JobLog" -Query -ReturnAsPSCustom
$job = Invoke-SqlQuery -Query $q -ConnectionName "JobLog" -Stream

$job | ForEach-Object {
$j = $_
$j.input = ConvertFrom-JsonAsHashtable $j.input
$j.output = ConvertFrom-JsonAsHashtable $j.input
If ( $ConvertInput -eq $true -or $ConvertOutput -eq $true ) {

$job | ForEach-Object {
$j = $_
If ( $ConvertInput -eq $true ) {
$j.input = ConvertFrom-JsonAsHashtable $j.input
}
If ( $ConvertOutput -eq $true ) {
Switch ( $j.returnformat ) {

# "ARRAY" {
# ConvertFrom-Json $job.output
# break
# }

"HASHTABLE" {
$j.output = ConvertFrom-JsonAsHashtable $j.output
break
}

default {
$j.output = ConvertFrom-Json $j.output
break
}

}

}

}

}

break
Expand All @@ -72,7 +118,7 @@ Function Get-JobLog {

$job


}

}
79 changes: 64 additions & 15 deletions AptecoPSFramework/public/jobs/Update-JobLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,58 @@ Function Update-JobLog {
...
#>
[cmdletbinding()]
[CmdletBinding(DefaultParameterSetName = 'Hashtable')]
param(

[Parameter(Mandatory=$true)][Int]$JobId # The Job ID that you have already got from the database
[Parameter(Mandatory=$true, ParameterSetName = 'Hashtable')]
[Parameter(Mandatory=$true, ParameterSetName = 'Array')]
[Int]$JobId # The Job ID that you have already got from the database

# Values to change
,[Parameter(Mandatory=$false)][Switch]$Finished = $false # Finished like 0 or 1
,[Parameter(Mandatory=$false)][String]$Status = "" # Status like "Finished" and others
,[Parameter(Mandatory=$false, ParameterSetName = 'Hashtable')]
[Parameter(Mandatory=$false, ParameterSetName = 'Array')]
[Switch]$Finished = $false # Finished like 0 or 1

,[Parameter(Mandatory=$false, ParameterSetName = 'Hashtable')]
[Parameter(Mandatory=$false, ParameterSetName = 'Array')]
[String]$Status = "" # Status like "Finished" and others

#,[Parameter(Mandatory=$false)][String]$Process = "" # Process ID
,[Parameter(Mandatory=$false)][String]$Plugin = "" # Plugin guid
,[Parameter(Mandatory=$false)][Int]$DebugMode = -1 # Debug mode like 0 or 1
,[Parameter(Mandatory=$false)][String]$Type = "" # Type like UPLOAD, MESSAGES, LISTS etc.
,[Parameter(Mandatory=$false)][Hashtable]$InputParam = [Hashtable]@{} # Input hashtable
,[Parameter(Mandatory=$false)][Int]$Inputrecords = -1 # Number of records that have been put in
,[Parameter(Mandatory=$false)][Int]$Successful = -1 # Successful records, only needed on uploads
,[Parameter(Mandatory=$false)][Int]$Failed = -1 # Failed records, only needed on uploads
,[Parameter(Mandatory=$false)][Int]$Totalseconds = -1 # Seconds in total, logged at the end
,[Parameter(Mandatory=$false)][Hashtable]$OutputParam = [Hashtable]@{} # Output hashtable (if it is suitable)
,[Parameter(Mandatory=$false, ParameterSetName = 'Hashtable')]
[Parameter(Mandatory=$false, ParameterSetName = 'Array')]
[String]$Plugin = "" # Plugin guid

,[Parameter(Mandatory=$false, ParameterSetName = 'Hashtable')]
[Parameter(Mandatory=$false, ParameterSetName = 'Array')]
[Int]$DebugMode = -1 # Debug mode like 0 or 1

,[Parameter(Mandatory=$false, ParameterSetName = 'Hashtable')]
[Parameter(Mandatory=$false, ParameterSetName = 'Array')]
[String]$Type = "" # Type like UPLOAD, MESSAGES, LISTS etc.

,[Parameter(Mandatory=$false, ParameterSetName = 'Hashtable')]
[Parameter(Mandatory=$false, ParameterSetName = 'Array')]
[Hashtable]$InputParam = [Hashtable]@{} # Input hashtable

,[Parameter(Mandatory=$false, ParameterSetName = 'Hashtable')]
[Parameter(Mandatory=$false, ParameterSetName = 'Array')]
[Int]$Inputrecords = -1 # Number of records that have been put in

,[Parameter(Mandatory=$false, ParameterSetName = 'Hashtable')]
[Parameter(Mandatory=$false, ParameterSetName = 'Array')]
[Int]$Successful = -1 # Successful records, only needed on uploads

,[Parameter(Mandatory=$false, ParameterSetName = 'Hashtable')]
[Parameter(Mandatory=$false, ParameterSetName = 'Array')]
[Int]$Failed = -1 # Failed records, only needed on uploads

,[Parameter(Mandatory=$false, ParameterSetName = 'Hashtable')]
[Parameter(Mandatory=$false, ParameterSetName = 'Array')]
[Int]$Totalseconds = -1 # Seconds in total, logged at the end

# Only one Output should be allowed
,[Parameter(Mandatory=$false, ParameterSetName = 'Hashtable')][Hashtable]$OutputParam = [Hashtable]@{} # Output hashtable (if it is suitable)
,[Parameter(Mandatory=$false, ParameterSetName = 'Array')][System.Collections.ArrayList]$OutputArray = [System.Collections.ArrayList]@() # Output array (if it is suitable)
)

Process {
Expand Down Expand Up @@ -80,8 +114,23 @@ Function Update-JobLog {
[void]$upd.Add("totalseconds = $( $Totalseconds )")
}

If ( $OutputParam.Keys.Count -gt 0 ) {
[void]$upd.Add("output = '$( ( ConvertTo-Json $OutputParam -Depth 99 ) )'")
Switch ( $PSCmdlet.ParameterSetName ) {

"Array" {
If ( $OutputArray.Count -gt 0 ) {
[void]$upd.Add("output = '$( ( ConvertTo-Json $OutputArray -Depth 99 ) )'")
}
[void]$upd.Add("returnformat = 'ARRAY'")
}

default {
If ( $OutputParam.Keys.Count -gt 0 ) {
[void]$upd.Add("output = '$( ( ConvertTo-Json $OutputParam -Depth 99 ) )'")
}
[void]$upd.Add("returnformat = 'HASHTABLE'")
break
}

}

$updateValues = $upd -join ", "
Expand Down
1 change: 1 addition & 0 deletions AptecoPSFramework/sql/joblog_create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ CREATE TABLE IF NOT EXISTS joblog (
,successful INTEGER
,failed INTEGER
,totalseconds INTEGER
,returnformat TEXT
,output TEXT
);

Expand Down

0 comments on commit d5c14c0

Please sign in to comment.