Skip to content

Commit

Permalink
Add module check and import for multi threads
Browse files Browse the repository at this point in the history
Multi instances were failing due to being unable to find Javinizer when
running in a separate thread if not installed by PowerShellGet
  • Loading branch information
jvlflame committed Jul 22, 2020
1 parent c000254 commit f4f85fc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
26 changes: 7 additions & 19 deletions src/Javinizer/Public/Javinizer.ps1
Expand Up @@ -742,35 +742,23 @@ function Javinizer {
$renamePreference = $false
}

<# With foreach-object -parallel
Get-VideoFile -Path $Path -Recurse:$Recurse -Settings $Settings | ForEach-Object -AsJob -ThrottleLimit $Settings.General.'multi-sort-throttle-limit' -Parallel {
$global:javinizerUpdatecheck = $using:javinizerUpdateCheck
if ($Javlibrary) {
$global:Session = $using:Session
}
if ($Settings.JavLibrary.'set-owned' -eq 'True') {
$global:javlibraryOwnedMovies = $using:javlibraryOwnedMovies
}
Javinizer -Path $_.FullName -DestinationPath:($using:DestinationPath) -ScriptRoot $using:ScriptRoot -Strict:($using:Strict) -MoveToFolder:($using:movePreference) -RenameFile:($using:renamePreference) -Force:($using:Force)
} | Out-Null
#>

$files = Get-VideoFile -Path $Path -Recurse:$Recurse -Settings $Settings
foreach ($file in $files) {
$filePath = $file.FullName
Start-ThreadJob -Name $file.BaseName -ThrottleLimit $Settings.General.'multi-sort-throttle-limit' -ScriptBlock {
$Settings = $using:Settings

# This will import the module in the separate Javinizer threads if the module isn't installed using PowerShellGet
if ($Settings.Other.'module-psm1-path') {
Import-Module $Settings.Other.'module-psm1-path'
}

$global:javinizerUpdatecheck = $using:javinizerUpdateCheck

if ($using:Javlibrary) {
$global:Session = $using:Session
}

$Settings = $using:Settings

Javinizer -Path $using:filePath -DestinationPath:($using:DestinationPath) -ScriptRoot $using:ScriptRoot -Strict:($using:Strict) -MoveToFolder:($using:movePreference) -RenameFile:($using:renamePreference) -Force:($using:Force)
} | Out-Null
}
Expand Down
3 changes: 2 additions & 1 deletion src/Javinizer/settings.ini
Expand Up @@ -118,6 +118,7 @@ request-timeout-sec=90
[Other]
# Log path will default to the javinizer.log file inside your module directory
log-path=
check-updates=True
check-updates=False
verbose-shell-output=True
debug-shell-output=False
module-psm1-path=

0 comments on commit f4f85fc

Please sign in to comment.