Job Tracker using EFPosh PowerShell Module
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
Function Start-CollectionMigration { | |
Param($Collection) | |
Start-Sleep -Milliseconds 250 | |
} | |
Function Test-CollectionMigration { | |
Param($Collection) | |
$Random = Get-Random -Minimum 1 -Maximum 10 | |
if($Random -eq 2){ | |
return $false | |
} | |
return $true | |
} | |
Function Get-CollectionsToMigrate { | |
10..99 | foreach-object { @{ 'CollectionId' = "PS1000$($_)" } } | |
} | |
Class JobTracker { | |
[string]$CollectionId | |
[bool]$Complete | |
} | |
$Tables = @( New-EFPoshEntityDefinition -Type 'JobTracker' -PrimaryKeys 'CollectionId' ) | |
$Context = New-EFPoshContext -SQLiteFile '.\JobTracker.sqlite' -Entities $Tables -EnsureCreated | |
$CollectionsToMigrate = Get-CollectionsToMigrate | |
Foreach($Collection in $CollectionsToMigrate) { | |
$Record = Search-EFPosh -Entity $Context.JobTracker -Expression { $_.CollectionId -eq $Collection.CollectionId } -FirstOrDefault | |
if($null -eq $Record){ | |
$Record = [JobTracker]::new() | |
$Record.CollectionId = $Collection.CollectionId | |
$Context.Add($Record) | |
$Context.SaveChanges() | |
} | |
if($false -eq $Record.Complete){ | |
Write-Host "Migrating $($Collection.CollectionId)" | |
Start-CollectionMigration -Collection $Collection | |
$Record.Complete = Test-CollectionMigration -Collection $Collection | |
$Context.SaveChanges() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment