Skip to content

Commit ac5498d

Browse files
committed
added offset for sync
1 parent 48d9855 commit ac5498d

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/Hsu.Db.Export.Spreadsheet/Options/ExportOptions.cs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class ExportOptions
99
public static string Export { get; set; } = "Export:Spreadsheet";
1010
public TimeSpan Trigger { get; set; } = TimeSpan.Zero;
1111
public TimeSpan Interval { get; set; } = TimeSpan.FromSeconds(30);
12+
[DefaultValue("06:00:00")] public TimeSpan? Offset { get; set; } = TimeSpan.FromHours(6);
1213
[DefaultValue("00:01:30")] public TimeSpan? Timeout { get; set; } = TimeSpan.FromSeconds(60);
1314
[DefaultValue(false)] public bool? Launch { get; set; }
1415
public string Path { get; set; } = string.Empty;

src/Hsu.Db.Export.Spreadsheet/Workers/DbDailySyncWorker.cs

+9-6
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ public class DbDailySyncWorker : BackgroundService, IDbDailySyncWorker
2525
private readonly IExportServiceFactory _factory;
2626
private readonly ExportOptions _options;
2727
private readonly TimeSpan _time;
28+
private readonly TimeSpan _offset;
2829
private readonly string _path;
2930

3031
public DbDailySyncWorker(ILogger<DbDailySyncWorker> logger, IFreeSql freeSql, IConfiguration configuration, IExportServiceFactory exportService)
3132
{
3233
_options = configuration.GetSection(ExportOptions.Export).Get<ExportOptions>() ?? throw new InvalidOperationException();
3334
_path = string.IsNullOrWhiteSpace(_options.Path) ? Path.Combine(Environment.CurrentDirectory, "Data") : _options.Path;
3435
_time = _options.Trigger;
36+
_offset = _options.Offset ?? TimeSpan.FromHours(6);
3537
_logger = logger;
3638
_freeSql = freeSql;
3739
_factory = exportService;
@@ -63,7 +65,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
6365

6466
if (launch)
6567
{
66-
await HandlerAsync(DateTime.Now,dir,types,timeout,stoppingToken);
68+
await HandlerAsync(DateTime.Now, _offset, dir, types, timeout, stoppingToken);
6769
}
6870

6971
while (!stoppingToken.IsCancellationRequested)
@@ -75,7 +77,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
7577
_logger.LogDebug("Sync Check: {ret}", ret);
7678
if (!ret) continue;
7779

78-
await HandlerAsync(now, dir, types, timeout, stoppingToken);
80+
await HandlerAsync(now, _offset, dir, types, timeout, stoppingToken);
7981
}
8082
catch (Exception ex)
8183
{
@@ -86,7 +88,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
8688
_logger.LogInformation("Sync Executed");
8789
}
8890

89-
protected async Task HandlerAsync(DateTime now,string dir, ConcurrentDictionary<string, TableInfo> types, int timeout, CancellationToken stoppingToken)
91+
protected async Task HandlerAsync(DateTime now,TimeSpan offset,string dir, ConcurrentDictionary<string, TableInfo> types, int timeout, CancellationToken stoppingToken)
9092
{
9193
_logger.LogInformation("Sync Handler Executing");
9294

@@ -125,7 +127,7 @@ protected async Task HandlerAsync(DateTime now,string dir, ConcurrentDictionary<
125127
_ => null
126128
};
127129

128-
var total = await FetchRecordAsync(_freeSql, timeout, table, date, _path, types[table.Code], exportService, _logger, stoppingToken);
130+
var total = await FetchRecordAsync(_freeSql, timeout, table, date,offset, _path, types[table.Code], exportService, _logger, stoppingToken);
129131
sw.Stop();
130132
_logger.LogInformation("Executing synchronously [{Table}]-{Date:yyyy-MM-dd} export to {Output} {Total} records completed used {Time}."
131133
, table.Name
@@ -189,6 +191,7 @@ private static async Task<int> FetchRecordAsync(IFreeSql freeSql,
189191
int timeout,
190192
TableOptions table,
191193
DateTime date,
194+
TimeSpan offset,
192195
string dir,
193196
TableInfo info,
194197
IExportService exportService,
@@ -205,13 +208,13 @@ CancellationToken stoppingToken
205208
{
206209
Field = $"a.{table.Filter}",
207210
Operator = DynamicFilterOperator.GreaterThanOrEqual,
208-
Value = date.Date
211+
Value = date.Date + offset
209212
},
210213
new()
211214
{
212215
Field = $"a.{table.Filter}",
213216
Operator = DynamicFilterOperator.LessThan,
214-
Value = date.Date.AddDays(1)
217+
Value = date.Date.AddDays(1) + offset
215218
}
216219
}
217220
};

0 commit comments

Comments
 (0)