Giter Club home page Giter Club logo

hangfire.mysql.core's Introduction

This project is no longer maintained, please use https://github.com/arnoldasgudas/Hangfire.MySqlStorage

Hangfire.MySql.Core Implementation

Hangfire.MySql.Core is based on Hangfire.MySqlStorage(https://github.com/arnoldasgudas/Hangfire.MySqlStorage)

I fix some bug and support .net standard 2.0

Latest version

MySql storage implementation of Hangfire - fire-and-forget, delayed and recurring tasks runner for .NET. Scalable and reliable background job runner. Supports multiple servers, CPU and I/O intensive, long-running and short-running jobs.

Now, support table prefix

services.AddHangfire(x => x.UseStorage(new MySqlStorage(Configuration.GetConnectionString("Hangfire"),new MySqlStorageOptions(){TablePrefix = "Custom"})));

Installation

Install MySQL

Run the following command in the NuGet Package Manager console to install Hangfire.MySql.Core:

Install-Package Hangfire.MySql.Core

Usage

Use one the following ways to initialize MySqlStorage:

  • Create new instance of MySqlStorage with connection string constructor parameter and pass it to Configuration with UseStorage method:
  GlobalConfiguration.Configuration.UseStorage(
    new MySqlStorage(connectionString));
  • There must be Allow User Variables set to true in the connection string. For example: server=127.0.0.1;uid=root;pwd=root;database={0};Allow User Variables=True
  • Alternatively one or more options can be passed as a parameter to MySqlStorage:
GlobalConfiguration.Configuration.UseStorage(
    new MySqlStorage(
        connectionString, 
        new MySqlStorageOptions
        {
            TransactionIsolationLevel = IsolationLevel.ReadCommitted,
            QueuePollInterval = TimeSpan.FromSeconds(15),
            JobExpirationCheckInterval = TimeSpan.FromHours(1),
            CountersAggregateInterval = TimeSpan.FromMinutes(5),
            PrepareSchemaIfNecessary = true,
            DashboardJobListLimit = 50000,
            TransactionTimeout = TimeSpan.FromMinutes(1),
            TablePrefix = "Hangfire"
        }));

Description of optional parameters:

  • TransactionIsolationLevel - transaction isolation level. Default is read committed.
  • QueuePollInterval - job queue polling interval. Default is 15 seconds.
  • JobExpirationCheckInterval - job expiration check interval (manages expired records). Default is 1 hour.
  • CountersAggregateInterval - interval to aggregate counter. Default is 5 minutes.
  • PrepareSchemaIfNecessary - if set to true, it creates database tables. Default is true.
  • DashboardJobListLimit - dashboard job list limit. Default is 50000.
  • TransactionTimeout - transaction timeout. Default is 1 minute.

How to limit number of open connections

Number of opened connections depends on Hangfire worker count. You can limit worker count by setting WorkerCount property value in BackgroundJobServerOptions:

app.UseHangfireServer(
   new BackgroundJobServerOptions
   {
      WorkerCount = 1
   });

More info: http://hangfire.io/features.html#concurrency-level-control

Dashboard

Hangfire provides a dashboard Dashboard More info: Hangfire Overview

Build

Please use Visual Studio or any other tool of your choice to build the solution

Test

In order to run unit tests and integrational tests set the following variables in you system environment variables (restart of Visual Studio is required):

Hangfire_SqlServer_ConnectionStringTemplate (default: server=127.0.0.1;uid=root;pwd=root;database={0};Allow User Variables=True)

Hangfire_SqlServer_DatabaseName (default: Hangfire.MySql.Tests)

hangfire.mysql.core's People

Contributors

dgrp avatar eapyl avatar konarpriyanku avatar mattheworres avatar rainy99 avatar stulzq avatar yuzd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hangfire.mysql.core's Issues

Deadlock found when trying to get lock

Hangfire.MySql.Core: 2.1.6-preview
MySqlConnector: 0.40.3

21:21:00.347|Hangfire.MySql.Core.ExpirationManager|ERROR
MySql.Data.MySqlClient.MySqlException (0x80004005): Deadlock found when trying to get lock; try restarting transaction ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Deadlock found when trying to get lock; try restarting transaction
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
   at MySqlConnector.Core.ResultSet.<ReadResultSetHeaderAsync>d__1.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\ResultSet.cs:line 43
   at MySql.Data.MySqlClient.MySqlDataReader.ActivateResultSet(ResultSet resultSet) in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 92
   at MySql.Data.MySqlClient.MySqlDataReader.<ReadFirstResultSetAsync>d__88.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 324
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySql.Data.MySqlClient.MySqlDataReader.<CreateAsync>d__87.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 314
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySqlConnector.Core.TextCommandExecutor.<ExecuteReaderAsync>d__3.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\TextCommandExecutor.cs:line 73
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySqlConnector.Core.TextCommandExecutor.<ExecuteNonQueryAsync>d__1.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\TextCommandExecutor.cs:line 26
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlCommand.cs:line 60
   at Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, CommandDefinition& command, Action`2 paramReader) in C:\projects\dapper\Dapper\SqlMapper.cs:line 2827
   at Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command) in C:\projects\dapper\Dapper\SqlMapper.cs:line 570
   at Dapper.SqlMapper.Execute(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable`1 commandTimeout, Nullable`1 commandType) in C:\projects\dapper\Dapper\SqlMapper.cs:line 443
   at Hangfire.MySql.Core.MySqlDistributedLock.AcquireLock(String resource, TimeSpan timeout)
   at Hangfire.MySql.Core.MySqlDistributedLock.Acquire()
   at Hangfire.MySql.Core.ExpirationManager.<>c__DisplayClass10_2.<Execute>b__0(MySqlConnection connection)

Any help? Thanks.

Install in visual studio for mac

Hi
I install
but when try to add code to config, get error

Error CS0012: The type 'MySqlConnection' is defined in an assembly that is not referenced. You must add a reference to assembly 'MySqlConnector, Version=0.28.0.0, Culture=neutral, PublicKeyToken=null'.

Deadlock found when trying to get lock

2020-07-06 07:13:15.1158 | Error | Deadlock found when trying to get lock; try restarting transaction

MySql.Data.MySqlClient.MySqlException (0x80004005): Deadlock found when trying to get lock; try restarting transaction
---> MySql.Data.MySqlClient.MySqlException (0x80004005): Deadlock found when trying to get lock; try restarting transaction
at MySqlConnector.Core.ResultSet.ReadResultSetHeaderAsync(IOBehavior ioBehavior) in C:\projects\mysqlconnector\src\MySqlConnector\Core\ResultSet.cs:line 49
at MySql.Data.MySqlClient.MySqlDataReader.ActivateResultSet() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 116
at MySql.Data.MySqlClient.MySqlDataReader.CreateAsync(CommandListPosition commandListPosition, ICommandPayloadCreator payloadCreator, IDictionary2 cachedProcedures, IMySqlCommand command, CommandBehavior behavior, IOBehavior ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 391 at MySqlConnector.Core.CommandExecutor.ExecuteReaderAsync(IReadOnlyList1 commands, ICommandPayloadCreator payloadCreator, CommandBehavior behavior, IOBehavior ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\Core\CommandExecutor.cs:line 62
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQueryAsync(IOBehavior ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlCommand.cs:line 226
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlCommand.cs:line 74
at Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, CommandDefinition& command, Action`2 paramReader) in C:\projects\dapper\Dapper\SqlMapper.cs:line 2836
at Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command) in C:\projects\dapper\Dapper\SqlMapper.cs:line 570
at Hangfire.MySql.Core.JobQueue.MySqlJobQueue.Dequeue(String[] queues, CancellationToken cancellationToken)
MySqlJobQueue.Dequeue => LogExtensions.ErrorException => AspNetCoreLog.Log

Hangfire.MySql.Core.ExpirationManager keeps deleting from `AggregatedCounter`

While the BackgroundJobServer starting, the logging output fast and endlessly. It seems ExpirationManager try to delete AggregatedCounter about 50+ times per second, and the removed count is -1.

I have tried 4 combinations.

These combinations have this problem.
MySQL 8 and Hangfire.MySql.Core 2.1.5
MySQL 8 and Hangfire.MySql.Core 2.1.6-preview
MySQL 5.7 and Hangfire.MySql.Core 2.1.6-preview

This combination works well:
MySQL 5.7 and Hangfire.MySql.Core 2.1.5

Project File:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Hangfire.Core" Version="1.6.20" />
    <PackageReference Include="Hangfire.MySql.Core" Version="2.1.6-preview" />
  </ItemGroup>
</Project>

Program.cs

using Hangfire.Logging;
using Hangfire.Logging.LogProviders;
using Hangfire.MySql.Core;
using System;

namespace Hangfire.Server
{
    class Program
    {
        private static void Main(string[] args)
        {
            GlobalConfiguration.Configuration.UseStorage(
                new MySqlStorage("Server=localhost;Database=hangfire;Uid=root;Pwd=123456;Allow User Variables=True"));

            LogProvider.SetCurrentLogProvider(new ColouredConsoleLogProvider());

            using (var server = new BackgroundJobServer())
            {
                Console.WriteLine("Hangfire Server started. Press any key to exit...");
                Console.ReadKey();
            }
        }
    }
}
2018-08-16 01:55:26 [DEBUG] (Hangfire.MySql.Core.ExpirationManager) removed records count=-1
2018-08-16 01:55:26 [DEBUG] (Hangfire.MySql.Core.ExpirationManager) delete from `AggregatedCounter` where ExpireAt < @now limit @count;
2018-08-16 01:55:26 [TRACE] (Hangfire.MySql.Core.MySqlDistributedLock) MySqlDistributedLock resource=expirationmanager, timeout=00:00:30
2018-08-16 01:55:26 [TRACE] (Hangfire.MySql.Core.MySqlDistributedLock) Acquire resource=expirationmanager, timeout=00:00:30
2018-08-16 01:55:26 [TRACE] (Hangfire.MySql.Core.MySqlDistributedLock) Release resource=expirationmanager
2018-08-16 01:55:26 [DEBUG] (Hangfire.MySql.Core.ExpirationManager) removed records count=-1
2018-08-16 01:55:26 [DEBUG] (Hangfire.MySql.Core.ExpirationManager) delete from `AggregatedCounter` where ExpireAt < @now limit @count;
2018-08-16 01:55:26 [TRACE] (Hangfire.MySql.Core.MySqlDistributedLock) MySqlDistributedLock resource=expirationmanager, timeout=00:00:30
2018-08-16 01:55:26 [TRACE] (Hangfire.MySql.Core.MySqlDistributedLock) Acquire resource=expirationmanager, timeout=00:00:30
2018-08-16 01:55:26 [TRACE] (Hangfire.MySql.Core.MySqlDistributedLock) Release resource=expirationmanager
2018-08-16 01:55:26 [DEBUG] (Hangfire.MySql.Core.ExpirationManager) removed records count=-1
2018-08-16 01:55:26 [DEBUG] (Hangfire.MySql.Core.ExpirationManager) delete from `AggregatedCounter` where ExpireAt < @now limit @count;

DataException: Error parsing column 6 (ExpireAt=2019/8/31 4:11:40 - Object)

An unhandled exception occurred while processing the request.
InvalidCastException: Unable to cast object of type 'MySql.Data.Types.MySqlDateTime' to type 'System.Nullable`1[System.DateTime]'.
Deserialize9e720b12-2d95-4f62-9beb-1e97f3e8ffd5(IDataReader )

DataException: Error parsing column 6 (ExpireAt=2019/8/31 4:11:40 - Object)
Dapper.SqlMapper.ThrowDataException(Exception ex, int index, IDataReader reader, object value) in SqlMapper.cs, line 3609

DataException: Error parsing column 6 (ExpireAt=2019/8/31 4:11:40 - Object)
Dapper.SqlMapper.ThrowDataException(Exception ex, int index, IDataReader reader, object value) in SqlMapper.cs
Deserialize9e720b12-2d95-4f62-9beb-1e97f3e8ffd5(IDataReader )
Dapper.SqlMapper.QueryImpl(IDbConnection cnn, CommandDefinition command, Type effectiveType)+MoveNext() in SqlMapper.cs
System.Collections.Generic.List..ctor(IEnumerable collection)
System.Linq.Enumerable.ToList(IEnumerable source)
Dapper.SqlMapper.Query(IDbConnection cnn, string sql, object param, IDbTransaction transaction, bool buffered, Nullable commandTimeout, Nullable commandType) in SqlMapper.cs
Hangfire.MySql.Core.Monitoring.MySqlMonitoringApi.EnqueuedJobs(MySqlConnection connection, IEnumerable jobIds)
Hangfire.MySql.Core.Monitoring.MySqlMonitoringApi+<>c__DisplayClass8_0.b__0(MySqlConnection connection)
Hangfire.MySql.Core.MySqlStorage+<>c__DisplayClass20_0.b__0(MySqlConnection connection)
Hangfire.MySql.Core.MySqlStorage.UseConnection(Func<MySqlConnection, T> func)
Hangfire.MySql.Core.MySqlStorage.UseTransaction(Func<MySqlConnection, T> func, Nullable isolationLevel)
Hangfire.MySql.Core.Monitoring.MySqlMonitoringApi.UseConnection(Func<MySqlConnection, T> action)
Hangfire.MySql.Core.Monitoring.MySqlMonitoringApi.EnqueuedJobs(string queue, int from, int perPage)
Hangfire.Dashboard.Pages.EnqueuedJobsPage.Execute()
Hangfire.Dashboard.RazorPage.TransformText(string body)
Hangfire.Dashboard.RazorPage.ToString()
Hangfire.Dashboard.RazorPageDispatcher.Dispatch(DashboardContext context)
Hangfire.Dashboard.AspNetCoreDashboardMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

error。。。

MySql.Data.MySqlClient.MySqlException (0x80004005): The table does not comply with the requirements by an external plugin.
at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
at Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, CommandDefinition& command, Action2 paramReader) in C:\projects\dapper\Dapper\SqlMapper.cs:line 2836 at Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command) in C:\projects\dapper\Dapper\SqlMapper.cs:line 570 at Dapper.SqlMapper.Execute(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable1 commandTimeout, Nullable1 commandType) in C:\projects\dapper\Dapper\SqlMapper.cs:line 443 at Hangfire.MySql.Core.MySqlDistributedLock.AcquireLock(String resource, TimeSpan timeout) in E:\sms2018\Hangfire.MySql.Core\Hangfire.MySql\MySqlDistributedLock.cs:line 56 at Hangfire.MySql.Core.MySqlDistributedLock.Acquire() in E:\sms2018\Hangfire.MySql.Core\Hangfire.MySql\MySqlDistributedLock.cs:line 93 at Hangfire.MySql.Core.MySqlStorageConnection.AcquireDistributedLock(String resource, TimeSpan timeout) in E:\sms2018\Hangfire.MySql.Core\Hangfire.MySql\MySqlStorageConnection.cs:line 35 at Hangfire.RecurringJobExtensions.AcquireDistributedRecurringJobLock(IStorageConnection connection, String recurringJobId, TimeSpan timeout) at Hangfire.RecurringJobManager.AddOrUpdate(String recurringJobId, Job job, String cronExpression, RecurringJobOptions options) at Hangfire.RecurringJobManagerExtensions.AddOrUpdate(IRecurringJobManager manager, String recurringJobId, Job job, String cronExpression, TimeZoneInfo timeZone, String queue) at Hangfire.RecurringJob.AddOrUpdate(Expression1 methodCall, String cronExpression, TimeZoneInfo timeZone, String queue)
at TxSms.Timed.Startup.<>c.b__1_81(HttpContext context) in E:\sms2018\TxSms.DP\src\TxSms.Timed\Startup.cs:line 464

The transaction associated with this command is not the connection's active transaction

after long time and searching finally find your nuget, but i get an error with dashboard, "The transaction associated with this command is not the connection's active transaction"
here's my code :

string connectionString = Configuration.GetConnectionString("DefaultConnection");
var storage = new MySqlStorage(connectionString, new MySqlStorageOptions
{
TransactionIsolationLevel = System.Data.IsolationLevel.ReadCommitted,
QueuePollInterval = TimeSpan.FromSeconds(15),
JobExpirationCheckInterval = TimeSpan.FromHours(1),
CountersAggregateInterval = TimeSpan.FromMinutes(5),
PrepareSchemaIfNecessary = true,
DashboardJobListLimit = 50000,
TransactionTimeout = TimeSpan.FromMinutes(1),
});
services.AddHangfire(x => x.UseStorage(storage));

app.UseHangfireServer();
app.UseHangfireDashboard("/Tasks", new DashboardOptions
{
Authorization = new[] { new HangfireAuthorizationFilter() },
AppPath = "/Home/Index"
});

Packages :

  • Hangfire "1.6.17"
  • Hangfire.MySql.Core "2.1.5"

and i get error :

InvalidOperationException: The transaction associated with this command is not the connection's active transaction.
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
MySql.Data.MySqlClient.MySqlCommand.ExecuteDbDataReader(CommandBehavior behavior) in MySqlCommand.cs
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
Dapper.SqlMapper.ExecuteReaderWithFlagsFallback(IDbCommand cmd, bool wasClosed, CommandBehavior behavior)
Dapper.SqlMapper+d__124.MoveNext()
System.Collections.Generic.List.AddEnumerable(IEnumerable enumerable)
System.Linq.Enumerable.ToList(IEnumerable source)
Dapper.SqlMapper.Query(IDbConnection cnn, string sql, object param, IDbTransaction transaction, bool buffered, Nullable commandTimeout, Nullable commandType)
Hangfire.MySql.Core.Monitoring.MySqlMonitoringApi.GetTimelineStats(MySqlConnection connection, IDictionary<string, DateTime> keyMaps)
Hangfire.MySql.Core.Monitoring.MySqlMonitoringApi.GetHourlyTimelineStats(MySqlConnection connection, string type)
Hangfire.MySql.Core.MySqlStorage+<>c__DisplayClass20_0.b__0(MySqlConnection connection)
Hangfire.MySql.Core.MySqlStorage.UseConnection(Func<MySqlConnection, T> func)
Hangfire.MySql.Core.MySqlStorage.UseTransaction(Func<MySqlConnection, T> func, Nullable isolationLevel)
Hangfire.Dashboard.Pages.HomePage.Execute()
Hangfire.Dashboard.RazorPage.TransformText(string body)
Hangfire.Dashboard.RazorPageDispatcher.Dispatch(DashboardContext context)
Hangfire.Dashboard.AspNetCoreDashboardMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Builder.Extensions.MapMiddleware+d__3.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Builder.RouterMiddleware+d__4.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware+d__6.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware+d__4.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware+d__6.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware+d__6.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware+d__7.MoveNext()

MySQL Syntax Exception with a fresh empty database

I am getting the folllowing error with a fresh empty database:
Tested with: 2.1.5 and 2.1.6 (pre-release)

MySql.Data.MySqlClient.MySqlException
HResult=0x80004005
Message=You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(6) NOT NULL,
ExpireAt datetime(6) DEFAULT NULL,
PRIMARY KEY (Id),
' at line 10
Source=MySqlConnector
StackTrace:
at MySql.Data.MySqlClient.MySqlDataReader.ActivateResultSet(ResultSet resultSet) in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 109
at MySql.Data.MySqlClient.MySqlDataReader.d__90.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 328
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MySql.Data.MySqlClient.MySqlDataReader.d__89.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 318
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MySqlConnector.Core.TextCommandExecutor.d__3.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\TextCommandExecutor.cs:line 73
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MySqlConnector.Core.TextCommandExecutor.d__1.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\TextCommandExecutor.cs:line 26
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlCommand.cs:line 60
at Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, CommandDefinition& command, Action2 paramReader) in C:\projects\dapper\Dapper\SqlMapper.cs:line 2827 at Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command) in C:\projects\dapper\Dapper\SqlMapper.cs:line 570 at Dapper.SqlMapper.Execute(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable1 commandTimeout, Nullable1 commandType) in C:\projects\dapper\Dapper\SqlMapper.cs:line 443 at Hangfire.MySql.Core.MySqlObjectsInstaller.Install(MySqlConnection connection) at Hangfire.MySql.Core.MySqlStorage..ctor(String connectionString, MySqlStorageOptions options) at xxx.WebAPI.Startup.<>c.<ConfigureServices>b__4_1(IGlobalConfiguration c) in D:\dev\xxx.WebAPI\xxx.WebAPI\Startup.cs:line 44 at Hangfire.HangfireServiceCollectionExtensions.<>c__DisplayClass0_0.<AddHangfire>b__9(IServiceProvider serviceProvider) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitSingleton(SingletonCallSite singletonCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(IServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass22_0.<RealizeService>b__0(ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider) at Hangfire.HangfireApplicationBuilderExtensions.ThrowIfNotConfigured(IApplicationBuilder app) at Hangfire.HangfireApplicationBuilderExtensions.UseHangfireServer(IApplicationBuilder app, BackgroundJobServerOptions options, IEnumerable1 additionalProcesses, JobStorage storage)
at xxx.WebAPI.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider) in D:\dev\xxx.WebAPI\xxx.WebAPI\Startup.cs:line 69

Inner Exception 1:
MySqlException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(6) NOT NULL,
ExpireAt datetime(6) DEFAULT NULL,
PRIMARY KEY (Id),
' at line 10

2.1.5 is not compatible with netcoreapp1.1

does this package not support netcoreapp1.1?
when i try to install nuget im getting this error
Package Hangfire.MySql.Core 2.1.5 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package Hangfire.MySql.Core 2.1.5 supports: netstandard2.0 (.NETStandard,Version=v2.0)

Update dependency of MySqlConnector to 0.40.*

As I was doing the dependency dance, I noticed that several of the Nuget packages I rely on will need to bump up to a newer version of the connector in order for all of them to move up. Hoping you can update it to the latest-ish version of the package without issue. Thanks!

GetJobs fails because Rank is a reserved keyword after 8.0.2

https://dev.mysql.com/doc/refman/8.0/en/keywords.html

        private JobList<TDto> GetJobs<TDto>(
            MySqlConnection connection,
            int from,
            int count,
            string stateName,
            Func<SqlJob, Job, Dictionary<string, string>, TDto> selector)
        {
            string jobsSql =
@"select * from (
  select j.*, s.Reason as StateReason, s.Data as StateData, @rownum := @rownum + 1 AS rank
  from Job j
    cross join (SELECT @rownum := 0) r
  left join State s on j.StateId = s.Id
  where j.StateName = @stateName
  order by j.Id desc
) as j where j.rank between @start and @end ";

You cannot cast a column to AS rank

In the file: Hangfire.MySql\Monitoring\MySqlMonitoringApi.cs

Similar issues in other files:

         public IEnumerable<int> GetEnqueuedJobIds(string queue, int @from, int perPage)
         {
             string sqlQuery = @"
 SET @rank=0;
 select r.JobId from (
   select jq.JobId, @rank := @rank+1 AS rank 
   from JobQueue jq
   where jq.Queue = @queue
   order by jq.Id
 ) as r
 where r.rank between @start and @end;";

GetRangeFromSet GetRangeFromList TrimList

I'd rename it and create a pull request, but I'm not sure if you use the Rank name somewhere for other purposes

Infinite loop in ExpirationManager

Hello!

I found an infinite loop in the ExpirationManager.cs.
After debugging the package i found out that this code returns -1 if there are more than one statements in the query:
removedCount = connection.Execute( String.Format( "select null from {0}where ExpireAt < @now; " + "delete from{0} where ExpireAt < @now limit @count;", table), new {now = DateTime.UtcNow, count = NumberOfRecordsInSinglePass});

There is a check if (removedCount > 0) which is working fine with the removedCount=-1 case too (fortunately), but the do-while's while (removedCount != 0); causes an infinite loop without any delays.

Removing the select null from {0}where ExpireAt < @now; from the connection.Execute solved the problem for me.
I also modified the exit point to while (removedCount > 0); just to be sure this could never cause an infinite loop again.

Cheers

Some real-time tasks are not performed

Some real-time tasks are not performed.
The FetchToken field of hangfire_jobqueue already has data, but the status in the job table is still Enqueued.

The maximum column size is 767 bytes.

pplication startup exception: MySql.Data.MySqlClient.MySqlException (0x80004005): Index column size too large. The maximum column size is 767 bytes. ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Index column size too large. The maximum column size is 767 bytes.

The Connectionstring was adding duplicate values. as a result of which the dictionary was not able to add duplicate key values in the below code snippet

The Connectionstring was adding duplicate values. as a result of which the dictionary was not able to add duplicate key values in the below code snippet

_connectionString.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => x.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries)) .Select(x => new { Key = x[0].Trim(), Value = x.Length>1? x[1].Trim():"" }) .ToDictionary(x => x.Key, x => x.Value, StringComparer.OrdinalIgnoreCase);

The expireat column in the job table requires an index.

hello
There is no index in the expireAt column of the job table.
My job table is more than 100 million.
inside hangfire, the following query is executed periodically.
ex) delete from Job where ExpireAt < timestamp('2019-06-27 08:43:08.153743') limit 1000
At this time, full scan occurs.
Therefore, i think that Index is needed in ExpireAt.

BackgroundJob.ContinueWith() has an error in the 2.1.6-preview

{Hangfire.BackgroundJobClientException: Background job creation failed. See inner exception for details. ---> System.MissingMethodException: Method not found: 'Void Newtonsoft.Json.JsonSerializerSettings.set_TypeNameAssemblyFormat(System.Runtime.Serialization.Formatters.FormatterAssemblyStyle)'.
at Hangfire.States.AwaitingState.SerializeData()
at Hangfire.MySql.Core.MySqlWriteOnlyTransaction.<>c__DisplayClass6_0.b__0(MySqlConnection x)
at Hangfire.MySql.Core.MySqlWriteOnlyTransaction.b__29_0(MySqlConnection connection)
at Hangfire.MySql.Core.MySqlStorage.<>c__DisplayClass19_0.b__0(MySqlConnection connection)
at Hangfire.MySql.Core.MySqlStorage.UseConnection[T](Func2 func) at Hangfire.MySql.Core.MySqlStorage.UseTransaction(Action1 action)
at Hangfire.Client.CoreBackgroundJobFactory.Create(CreateContext context)
at Hangfire.Client.BackgroundJobFactory.<>c__DisplayClass7_0.b__0()
at Hangfire.Client.BackgroundJobFactory.InvokeClientFilter(IClientFilter filter, CreatingContext preContext, Func1 continuation) at Hangfire.Client.BackgroundJobFactory.Create(CreateContext context) at Hangfire.BackgroundJobClient.Create(Job job, IState state) --- End of inner exception stack trace --- at Hangfire.BackgroundJobClient.Create(Job job, IState state) at Hangfire.BackgroundJob.ContinueWith[T](String parentId, Expression1 methodCall, JobContinuationOptions options)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.