Skip to content

Commit

Permalink
Compatibility with new Npgsql (#35)
Browse files Browse the repository at this point in the history
* Enhanced to support Hangfire 1.5, fixed tests.

* Added word "revised" to nuspecs.

* Breaking - Uses 'Hangfire.Core' 1.5.7
* Breaking - Uses 'Npgsql' 3.1.3
* Updated to Newtonsoft.Json 8.0.3
* Updated Moq to 4.5.8

* Fixes "NotSupportedException: Specified method is not supported." error in dashboard.

* Added zero processin latency

* Updated nuspec file to reflect latest merge issues (#33 and $31 of original frankhommers repo)
  • Loading branch information
vytautask authored Aug 8, 2016
1 parent 0b71961 commit ce0e1e3
Show file tree
Hide file tree
Showing 34 changed files with 4,629 additions and 3,780 deletions.
4 changes: 2 additions & 2 deletions .nuget/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<package id="7-Zip.CommandLine" version="9.20.0" />
<package id="Hangfire.Build" version="0.1.3" />
<package id="ILMerge" version="2.14.1208" targetFramework="net45" />
<package id="psake" version="4.4.1" />
<package id="xunit.runners" version="1.9.2" />
<package id="psake" version="4.5.0" />
<package id="xunit.runner.console" version="2.1.0" />
</packages>
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,21 @@ Download all files from this repository, add the Hangfire.PostgreSql.csproj to y
Reference it in your project, and you are ready to go by using:

```csharp
app.UseHangfire(config =>
{
config.UsePostgreSqlStorage("<connection string or its name>");
config.UseServer();
});
app.UseHangfireServer(new BackgroundJobServerOptions(), new PostgreSqlStorage("<connection string or its name>"));
app.UseHangfireDashboard();
```


Related Projects
-----------------

* [Hangfire.Core](https://github.com/HangfireIO/Hangfire)
* [Hangfire.PostgreSql] by frankhommers (https://github.com/frankhommers/Hangfire.PostgreSql)

License
--------

Copyright © 2014 Frank Hommers <http://hmm.rs/Hangfire.PostgreSql>.
Copyright © 2014-2016 Frank Hommers <http://hmm.rs/Hangfire.PostgreSql> and others (Burhan Irmikci (barhun), Zachary Sims(zsims), kgamecarter, Stafford Williams (staff0rd), briangweber, Viktor Svyatokha (ahydrax), Christopher Dresel (Dresel), Vytautas Kasparavičius (vytautask).

Hangfire.PostgreSql is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
Expand Down
2 changes: 1 addition & 1 deletion build.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@echo off
.nuget\NuGet.exe install .nuget\packages.config -OutputDirectory packages
powershell.exe -NoProfile -ExecutionPolicy unrestricted -Command "& {Import-Module '.\packages\psake.*\tools\psake.psm1'; invoke-psake .\psake-project.ps1 %*; if ($LastExitCode -and $LastExitCode -ne 0) {write-host "ERROR CODE: $LastExitCode" -fore RED; exit $lastexitcode} }"
powershell.exe -NoProfile -ExecutionPolicy unrestricted -Command "& {Import-Module '.\packages\psake.*\tools\psake.psm1'; invoke-psake .\psake-project.ps1 -framework "4.6" %*; if ($LastExitCode -and $LastExitCode -ne 0) {write-host "ERROR CODE: $LastExitCode" -fore RED; exit $lastexitcode} }"
7 changes: 2 additions & 5 deletions content/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ namespace MyWebApplication
{
public void Configuration(IAppBuilder app)
{
app.UseHangfire(config =>
{
config.UsePostgreSqlStorage("<name or connection string>");
config.UseServer();
});
app.UseHangfireServer(new BackgroundJobServerOptions(), new PostgreSqlStorage("<connection string or its name>"));
app.UseHangfireDashboard();;
}
}
}
51 changes: 25 additions & 26 deletions nuspecs/Hangfire.PostgreSql.nuspec
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
<?xml version="1.0"?>
<package >
<metadata>
<id>Hangfire.PostgreSql</id>
<version>1.3.1</version>
<title>Hangfire PostgreSql Storage</title>
<authors>Frank Hommers</authors>
<owners>frankhommers</owners>
<projectUrl>http://hmm.rs/Hangfire.PostgreSql</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<licenseUrl>https://raw.github.com/frankhommers/Hangfire.PostgreSql/master/LICENSE.md</licenseUrl>
<description>PostgreSql storage implementation for Hangfire (background job system for ASP.NET applications).</description>
<copyright>Copyright &#169; 2014 Frank Hommers</copyright>
<tags>Hangfire PostgreSql Postgres</tags>
<releaseNotes>
https://github.com/frankhommers/Hangfire.PostgreSql/releases
1.3.4
* Breaking - Use 'Hangfire.Core' 1.3.4.
* Breaking - Use 'Npgsql' 2.2.4.1.
* Shows schema name in dashboard
* Fix GetTimelineStats / GetHourlyTimelineStats incorrect order
</releaseNotes>
<dependencies>
<dependency id="Hangfire.Core" version="1.3.4" />
<dependency id="Dapper" version="1.38" />
<dependency id="Npgsql" version="2.2.4.1" />
</dependencies>
<id>Hangfire.PostgreSql</id>
<version>1.4.0</version>
<title>Hangfire PostgreSql Storage</title>
<authors>Frank Hommers and others (Burhan Irmikci (barhun), Zachary Sims(zsims), kgamecarter, Stafford Williams (staff0rd), briangweber, Viktor Svyatokha (ahydrax), Christopher Dresel (Dresel), Vytautas Kasparavičius (vytautask)</authors>
<owners>frankhommers</owners>
<projectUrl>http://hmm.rs/Hangfire.PostgreSql</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<licenseUrl>https://raw.github.com/frankhommers/Hangfire.PostgreSql/master/LICENSE.md</licenseUrl>
<description>PostgreSql storage implementation for Hangfire (background job system for ASP.NET applications).</description>
<summary>Latest build of Hangfire.PostgreSql with many fixes and new PostgreSql driver support.</summary>
<copyright>Copyright &#169; 2014-2016 Frank Hommers and others</copyright>
<tags>Hangfire PostgreSql Postgres</tags>
<releaseNotes>
https://github.com/frankhommers/Hangfire.PostgreSql/releases
1.4.0
* Compatibility with new Npgsql #33 (https://github.com/frankhommers/Hangfire.PostgreSql/issues/33)
* Fixed "Could not place a lock on the resource: Lock timeout" #31 (https://github.com/frankhommers/Hangfire.PostgreSql/issues/31)
</releaseNotes>
<dependencies>
<dependency id="Hangfire.Core" version="1.5.7" />
<dependency id="Dapper" version="1.40" />
<dependency id="Npgsql" version="3.1.3" />
</dependencies>
</metadata>
<files>
<file src="Net45\Hangfire.PostgreSql.dll" target="lib\net45" />
<file src="Net45\Hangfire.PostgreSql.xml" target="lib\net45" />
<file src="Net45\Hangfire.PostgreSql.dll" target="lib\net452" />
<file src="Net45\Hangfire.PostgreSql.xml" target="lib\net452" />
</files>
</package>
271 changes: 270 additions & 1 deletion psake-project.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
Properties {
$solution = "Hangfire.PostgreSql.sln"

### Directories
$base_dir = resolve-path .
$build_dir = "$base_dir\build"
$src_dir = "$base_dir\src"
$tests_dir = "$base_dir\tests"
$package_dir = "$base_dir\packages"
$nuspec_dir = "$base_dir\nuspecs"
$temp_dir = "$build_dir\Temp"
$framework_dir = $env:windir + "\Microsoft.Net\Framework\v4.0.30319"

### Tools
$nuget = "$base_dir\.nuget\nuget.exe"
$ilmerge = "$package_dir\ilmerge.*\tools\ilmerge.exe"
$xunit = "$package_dir\xunit.runner.console.*\tools\xunit.console.exe"
$7zip = "$package_dir\7-Zip.CommandLine.*\tools\7za.exe"

### AppVeyor-related
$appVeyorConfig = "$base_dir\appveyor.yml"
$appVeyor = $env:APPVEYOR

### Project information
$solution_path = "$base_dir\$solution"
$config = "Release"
$sharedAssemblyInfo = "$src_dir\SharedAssemblyInfo.cs"
}
Include "packages\Hangfire.Build.*\tools\psake-common.ps1"

Task Default -Depends Collect

Expand Down Expand Up @@ -30,3 +54,248 @@ Task Pack -Depends Collect -Description "Create NuGet packages and archive files
Create-Package "Hangfire.PostgreSql" $version
}

## Tasks

Task Restore -Description "Restore NuGet packages for solution." {
"Restoring NuGet packages for '$solution'..."
Exec { .$nuget restore $solution }
}

Task Clean -Description "Clean up build and project folders." {
Clean-Directory $build_dir

if ($solution) {
"Cleaning up '$solution'..."
Exec { msbuild $solution_path /target:Clean /nologo /verbosity:minimal }
}
}

Task Compile -Depends Clean, Restore -Description "Compile all the projects in a solution." {
"Compiling '$solution'..."

$extra = $null
if ($appVeyor) {
$extra = "/logger:C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
}

Exec { msbuild $solution_path /p:Configuration=$config /nologo /verbosity:minimal $extra }
}

Task Version -Description "Patch AssemblyInfo and AppVeyor version files." {
$newVersion = Read-Host "Please enter a new version number (major.minor.patch)"
Update-SharedVersion $newVersion
Update-AppVeyorVersion $newVersion
}

## Functions

### Test functions

function Run-XunitTests($project) {
$assembly = Get-Assembly $tests_dir $project

if ($appVeyor) {
Exec { xunit.console.clr4 $assembly /appveyor }
} else {
Exec { .$xunit $assembly }
}
}

### Merge functions

function Merge-Assembly($project, $internalizeAssemblies) {
$projectDir = $project
$projectAssembly = $project

if ($project -Is [System.Array]) {
$projectDir = $project[0]
$projectAssembly = $project[1]
}

"Merging '$projectAssembly' with $internalizeAssemblies..."

$internalizePaths = @()

foreach ($assembly in $internalizeAssemblies) {
$internalizePaths += Get-SrcAssembly $projectDir $assembly
}

$primaryAssemblyPath = Get-SrcAssembly $projectDir $projectAssembly

Create-Directory $temp_dir

Exec { .$ilmerge /targetplatform:"v4,$framework_dir" `
/out:"$temp_dir\$projectAssembly.dll" `
/target:library `
/internalize `
$primaryAssemblyPath `
$internalizePaths `
}

Move-Files "$temp_dir\$projectAssembly.*" (Get-SrcOutputDir $projectDir)
}

### Collect functions

function Collect-Tool($source) {
"Collecting tool '$source'..."

$destination = "$build_dir\Tools"

Create-Directory $destination
Copy-Files "$source" $destination
}

function Collect-Content($source) {
"Collecting content '$source'..."

$destination = "$build_dir\Content"

Create-Directory $destination
Copy-Files "$source" $destination
}

function Collect-Assembly($project, $version) {
$projectDir = $project
$assembly = $project

if ($project -Is [System.Array]) {
$projectDir = $project[0]
$assembly = $project[1]
}

"Collecting assembly '$assembly.dll' into '$version'..."

$source = (Get-SrcOutputDir $projectDir) + "\$assembly.*"
$destination = "$build_dir\$version"

Create-Directory $destination
Copy-Files $source $destination
}

### Pack functions

function Create-Package($project, $version) {
Create-Directory $temp_dir
Copy-Files "$nuspec_dir\$project.nuspec" $temp_dir

Try {
Replace-Content "$nuspec_dir\$project.nuspec" '0.0.0' $version
Exec { .$nuget pack "$nuspec_dir\$project.nuspec" -OutputDirectory "$build_dir" -BasePath "$build_dir" -Version $version -Symbols }
}
Finally {
Move-Files "$temp_dir\$project.nuspec" $nuspec_dir
}
}

### Version functions

function Get-BuildVersion {
$version = Get-SharedVersion
$buildNumber = $env:APPVEYOR_BUILD_NUMBER

if ($env:APPVEYOR_REPO_TAG -ne "True" -And $buildNumber -ne $null) {
$version += "-build-" + $buildNumber.ToString().PadLeft(5, '0')
}

return $version
}

function Get-SharedVersion {
$line = Get-Content "$sharedAssemblyInfo" | where {$_.Contains("AssemblyVersion")}
$line.Split('"')[1]
}

function Update-SharedVersion($version) {
Check-Version($version)

$versionPattern = 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)'
$versionAssembly = 'AssemblyVersion("' + $version + '")';

if (Test-Path $sharedAssemblyInfo) {
"Patching $sharedAssemblyInfo..."
Replace-Content "$sharedAssemblyInfo" $versionPattern $versionAssembly
}
}

function Update-AppveyorVersion($version) {
Check-Version($version)

$versionPattern = "version: [0-9]+(\.([0-9]+|\*)){1,3}"
$versionReplace = "version: $version"

if (Test-Path $appVeyorConfig) {
"Patching $appVeyorConfig..."
Replace-Content "$appVeyorConfig" $versionPattern $versionReplace
}
}

function Check-Version($version) {
if ($version -notmatch "[0-9]+(\.([0-9]+|\*)){1,3}") {
Write-Error "Version number incorrect format: $version"
}
}

### Archive functions

function Create-Archive($name) {
Remove-Directory $temp_dir
Create-Zip "$build_dir\$name.zip" "$build_dir"
}

function Create-Zip($file, $dir){
if (Test-Path -path $file) { Remove-Item $file }
Create-Directory $dir
Exec { & $7zip a -mx -tzip $file $dir\* }
}

### Common functions

function Create-Directory($dir) {
New-Item -Path $dir -Type Directory -Force > $null
}

function Clean-Directory($dir) {
If (Test-Path $dir) {
"Cleaning up '$dir'..."
Remove-Item "$dir\*" -Recurse -Force
}
}

function Remove-Directory($dir) {
if (Test-Path $dir) {
"Removing '$dir'..."
Remove-Item $dir -Recurse -Force
}
}

function Copy-Files($source, $destination) {
Copy-Item "$source" $destination -Force > $null
}

function Move-Files($source, $destination) {
Move-Item "$source" $destination -Force > $null
}

function Replace-Content($file, $pattern, $substring) {
(gc $file) -Replace $pattern, $substring | sc $file
}

function Get-SrcAssembly($project, $assembly) {
return Get-Assembly $src_dir $project $assembly
}

function Get-SrcOutputDir($project) {
return Get-OutputDir $src_dir $project
}

function Get-Assembly($dir, $project, $assembly) {
if (!$assembly) {
$assembly = $project
}
return (Get-OutputDir $dir $project) + "\$assembly.dll"
}

function Get-OutputDir($dir, $project) {
return "$dir\$project\bin\$config"
}
Loading

1 comment on commit ce0e1e3

@vytautask
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should fix #31 (misstyped with "$" symbol).

Please sign in to comment.