Skip to content

Instantly share code, notes, and snippets.

@odinserj
odinserj / SkipWhenPreviousJobIsRunningAttribute.cs
Last active May 3, 2024 17:03
SkipWhenPreviousJobIsRunningAttribute.cs
// Zero-Clause BSD (more permissive than MIT, doesn't require copyright notice)
//
// Permission to use, copy, modify, and/or distribute this software for any purpose
// with or without fee is hereby granted.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
// OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
// Zero-Clause BSD (more permissive than MIT, doesn't require copyright notice)
//
// Permission to use, copy, modify, and/or distribute this software for any purpose
// with or without fee is hereby granted.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
// OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
// Copyright © 2020 Sergey Odinokov
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the “Software”), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
@odinserj
odinserj / DebounceAttribute.cs
Created April 18, 2017 12:41
DebounceAttribute
public sealed class DebounceAttribute : JobFilterAttribute, IElectStateFilter
{
private readonly string _resourceFormat;
private readonly int _milliseconds;
public DebounceAttribute(string resourceFormat, int milliseconds)
{
_resourceFormat = resourceFormat ?? throw new ArgumentNullException(nameof(resourceFormat));
_milliseconds = milliseconds;
}
@odinserj
odinserj / SkipIfExistsAttribute.cs
Last active April 15, 2022 02:46
SkipIfExistsAttribute.cs
// Zero-Clause BSD (more permissive than MIT, doesn't require copyright notice)
//
// Permission to use, copy, modify, and/or distribute this software for any purpose
// with or without fee is hereby granted.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
// OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
@odinserj
odinserj / MutexAttribute.cs
Last active January 15, 2022 12:56
MutexAttribute.cs
using System;
using System.Collections.Generic;
using System.Linq;
using Hangfire.Common;
using Hangfire.States;
using Hangfire.Storage;
namespace Hangfire.Pro
{
/// <summary>
using System;
using System.Threading.Tasks;
using Hangfire;
using Hangfire.Common;
using Hangfire.States;
using Hangfire.Storage;
using Microsoft.Owin.Hosting;
using Owin;
namespace ConsoleApp71
@odinserj
odinserj / docker-compose.yml
Last active November 29, 2019 14:46
ProGet using docker compose
version: '2'
services:
nginx:
image: jwilder/nginx-proxy
container_name: nginx-proxy
environment:
- DEFAULT_HOST=nuget.hangfire.io
links:
- proget
ports:
@odinserj
odinserj / App.cs
Last active October 24, 2019 08:56
GlobalConfiguration.Configuration
.UseFilter(new OverrideJobIdFilter());
OverrideJobIdFilter.SetOverriddenId(Guid.Parse("266AC580-4FF9-4E72-B06A-CA20D7664B9E"));
BackgroundJob.Enqueue(() => Empty());
using System;
using System.Linq.Expressions;
using Hangfire.Annotations;
using Hangfire.Common;
using Hangfire.States;
namespace Hangfire
{
public static class RecurringJobManagerExtensions
{