Skip to content

Commit

Permalink
MySqlConnection 1 + Dapper 2
Browse files Browse the repository at this point in the history
  • Loading branch information
MiloszKrajewski committed May 7, 2021
1 parent 31b6e5e commit d8dc876
Show file tree
Hide file tree
Showing 14 changed files with 191 additions and 230 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.0 (2021/05/07)
* CHANGED: upgraded MySqlConnector to v1
* CHANGED: upgraded Dapper to v2

## 0.0.20 (2021/04/27)
* CHANGED: keep completed and failed jobs (for a period of time)
* ADDED: pruning archived (completed and failed) jobs
Expand Down
6 changes: 3 additions & 3 deletions Common.targets
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project>
<PropertyGroup>
<Version>0.0.20</Version>
<AssemblyVersion>0.0.20</AssemblyVersion>
<FileVersion>0.0.20</FileVersion>
<Version>0.1.0</Version>
<AssemblyVersion>0.1.0</AssemblyVersion>
<FileVersion>0.1.0</FileVersion>
</PropertyGroup>
<PropertyGroup>
<!-- Χρόνος -->
Expand Down
4 changes: 2 additions & 2 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ nuget System.Interactive
nuget K4os.Async.Batch
nuget K4os.Quarterback

nuget MySqlConnector 0.56.0
nuget MySqlConnector ~> 1
nuget Npgsql ~> 4
nuget Microsoft.Data.Sqlite ~> 3
nuget System.Data.SqlClient ~> 4

nuget Dapper ~> 1
nuget Dapper ~> 2
nuget Polly ~> 7
nuget Newtonsoft.Json ~> 10
nuget MediatR ~> 8
Expand Down
346 changes: 159 additions & 187 deletions paket.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/K4os.Shared/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

// ReSharper disable UnusedMember.Global
// ReSharper disable UnusedType.Global
Expand Down
2 changes: 0 additions & 2 deletions src/K4os.Xpovoc.Core/Db/DbJobScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace K4os.Xpovoc.Core.Db
{
public class DbJobScheduler: IJobScheduler
{
private static readonly TimeSpan VeryLongTime = TimeSpan.FromDays(5*365);

private readonly ILoggerFactory _loggerFactory;
private readonly IDateTimeSource _dateTimeSource;
private readonly IDbJobStorage _jobStorage;
Expand Down
12 changes: 5 additions & 7 deletions src/K4os.Xpovoc.Core/Sql/AnySqlMigrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace K4os.Xpovoc.Core.Sql
{
public abstract class AnySqlMigrator
{
private string _productId;
private readonly string _productId;
private readonly IDbConnection _connection;
private readonly Migration[] _migrations;

Expand Down Expand Up @@ -50,12 +50,10 @@ private void ApplyMigration(IDbConnection connection, string id, string script)
{
// NOTE: Some operations cannot be executed in transactions (create table?)
// we will need some mechanism to handle that if we need it
using (var transaction = connection.BeginTransaction())
{
ExecuteScript(connection, transaction, script);
MarkMigrationDone(connection, transaction, id);
transaction.Commit();
}
using var transaction = connection.BeginTransaction();
ExecuteScript(connection, transaction, script);
MarkMigrationDone(connection, transaction, id);
transaction.Commit();
}

protected abstract void ExecuteScript(
Expand Down
16 changes: 6 additions & 10 deletions src/K4os.Xpovoc.Core/Sql/DefaultJobSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,17 @@ protected virtual BinaryFormatter CreateFormatter() =>
public string Serialize(object job)
{
var formatter = CreateFormatter();
using (var stream = new MemoryStream())
{
formatter.Serialize(stream, job);
stream.Flush();
return Convert.ToBase64String(stream.ToArray());
}
using var stream = new MemoryStream();
formatter.Serialize(stream, job);
stream.Flush();
return Convert.ToBase64String(stream.ToArray());
}

public object Deserialize(string payload)
{
var formatter = CreateFormatter();
using (var stream = new MemoryStream(Convert.FromBase64String(payload)))
{
return formatter.Deserialize(stream);
}
using var stream = new MemoryStream(Convert.FromBase64String(payload));
return formatter.Deserialize(stream);
}
}
}
2 changes: 0 additions & 2 deletions src/K4os.Xpovoc.Db.Test/Integrations/MsSqlStorageTest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System.Data.SqlClient;
using System.Threading.Tasks;
using Dapper;
using K4os.Xpovoc.Core.Db;
using K4os.Xpovoc.MsSql;
using Xunit;

namespace K4os.Xpovoc.Db.Test.Integrations
{
Expand Down
4 changes: 1 addition & 3 deletions src/K4os.Xpovoc.Db.Test/Integrations/MySqlStorageTest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System.Threading.Tasks;
using Dapper;
using K4os.Xpovoc.Core.Db;
using K4os.Xpovoc.MySql;
using MySql.Data.MySqlClient;
using Xunit;
using MySqlConnector;

namespace K4os.Xpovoc.Db.Test.Integrations
{
Expand Down
2 changes: 0 additions & 2 deletions src/K4os.Xpovoc.Db.Test/Integrations/PgSqlStorageTest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System.Threading.Tasks;
using Dapper;
using K4os.Xpovoc.Core.Db;
using K4os.Xpovoc.PgSql;
using Npgsql;
using Xunit;

namespace K4os.Xpovoc.Db.Test.Integrations
{
Expand Down
2 changes: 1 addition & 1 deletion src/K4os.Xpovoc.MySql/MySqlExecutionPolicy.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using MySqlConnector;
using Polly;

namespace K4os.Xpovoc.MySql
Expand Down
2 changes: 1 addition & 1 deletion src/K4os.Xpovoc.MySql/MySqlJobStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using K4os.Xpovoc.Abstractions;
using K4os.Xpovoc.Core.Sql;
using K4os.Xpovoc.MySql.Resources;
using MySql.Data.MySqlClient;
using MySqlConnector;

namespace K4os.Xpovoc.MySql
{
Expand Down
18 changes: 9 additions & 9 deletions src/Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ private static async Task Execute(
var scheduler = new DbJobScheduler(null, mysqlStorage, handler, schedulerConfig);
// var scheduler = new RxJobScheduler(loggerFactory, handler, Scheduler.Default);

var producer = Task.CompletedTask;
var producerSpeed = Task.CompletedTask;
// var producer = Task.Run(() => Producer(token, scheduler), token);
// var producerSpeed = Task.Run(
// () => Measure(
// token,
// loggerFactory,
// "Produced",
// () => Volatile.Read(ref _producedCount)));
// var producer = Task.CompletedTask;
// var producerSpeed = Task.CompletedTask;
var producer = Task.Run(() => Producer(token, scheduler), token);
var producerSpeed = Task.Run(
() => Measure(
token,
loggerFactory,
"Produced",
() => Volatile.Read(ref _producedCount)));

var consumedSpeed = Task.Run(
() => Measure(
Expand Down

0 comments on commit d8dc876

Please sign in to comment.