Skip to content

Commit aae494e

Browse files
committed
修复测试用例
1 parent 3b35033 commit aae494e

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/DotnetSpider.MySql/Scheduler/MySqlQueueScheduler.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,27 @@ public async Task InitializeAsync(string spiderId)
5252

5353
await using var conn = new MySqlConnection(_options.ConnectionString);
5454
await conn.ExecuteAsync($@"
55-
CREATE TABLE IF NOT EXISTS {spiderId}_set
55+
CREATE TABLE IF NOT EXISTS `{spiderId}_set`
5656
(
5757
hash varchar(32) not null primary key,
5858
request mediumblob not null,
5959
state char(1),
6060
creation_time timestamp default CURRENT_TIMESTAMP not null
6161
);");
6262
await conn.ExecuteAsync($@"
63-
CREATE TABLE IF NOT EXISTS {spiderId}_queue
63+
CREATE TABLE IF NOT EXISTS `{spiderId}_queue`
6464
(
6565
id int auto_increment primary key,
6666
hash varchar(32) not null,
6767
request mediumblob not null,
6868
constraint {spiderId}_queue_hash_uindex unique (hash)
6969
);");
70-
_totalSql = $"SELECT COUNT(*) FROM {_spiderId}_set";
71-
_resetDuplicateCheckSql = $"TRUNCATE {_spiderId}_set; TRUNCATE {_spiderId}_queue;";
72-
_insertSetSql = $"INSERT IGNORE INTO {_spiderId}_set (hash, request) VALUES (@Hash, @Request); ";
73-
_insertQueueSql = $"INSERT IGNORE INTO {_spiderId}_queue (hash, request) VALUES (@Hash, @Request);";
74-
_successSql = $"UPDATE {_spiderId}_set SET state = 'S' WHERE hash = @Hash;";
75-
_failSql = $"UPDATE {_spiderId}_set SET state = 'E' WHERE hash = @Hash;";
70+
_totalSql = $"SELECT COUNT(*) FROM `{_spiderId}_set`";
71+
_resetDuplicateCheckSql = $"TRUNCATE `{_spiderId}_set`; TRUNCATE {_spiderId}_queue;";
72+
_insertSetSql = $"INSERT IGNORE INTO `{_spiderId}_set` (hash, request) VALUES (@Hash, @Request); ";
73+
_insertQueueSql = $"INSERT IGNORE INTO `{_spiderId}_queue` (hash, request) VALUES (@Hash, @Request);";
74+
_successSql = $"UPDATE `{_spiderId}_set` SET state = 'S' WHERE hash = @Hash;";
75+
_failSql = $"UPDATE `{_spiderId}_set` SET state = 'E' WHERE hash = @Hash;";
7676
}
7777

7878
public async Task<IEnumerable<Request>> DequeueAsync(int count = 1)
@@ -106,7 +106,7 @@ public async Task<IEnumerable<Request>> DequeueAsync(int count = 1)
106106
var ids = string.Join(",", rows.Select(x => $"'{x["id"]}'"));
107107
var hashes = string.Join(",", rows.Select(x => $"'{x["hash"]}'"));
108108
await conn.ExecuteAsync(
109-
$"DELETE FROM {_spiderId}_queue WHERE id IN ({ids}); UPDATE {_spiderId}_set SET state = 'P' WHERE hash IN ({hashes});",
109+
$"DELETE FROM `{_spiderId}_queue` WHERE id IN ({ids}); UPDATE `{_spiderId}_set` SET state = 'P' WHERE hash IN ({hashes});",
110110
null, transaction);
111111
await transaction.CommitAsync();
112112
var list = new List<Request>();
@@ -189,15 +189,15 @@ public virtual async Task ResetDuplicateCheckAsync()
189189
public async Task CleanAsync()
190190
{
191191
await using var conn = new MySqlConnection(_options.ConnectionString);
192-
await conn.ExecuteAsync($"DROP table {_spiderId}_set");
193-
await conn.ExecuteAsync($"DROP table {_spiderId}_queue");
192+
await conn.ExecuteAsync($"DROP table `{_spiderId}_set`");
193+
await conn.ExecuteAsync($"DROP table `{_spiderId}_queue`");
194194
}
195195

196196
public async Task ReloadAsync()
197197
{
198198
await using var conn = new MySqlConnection(_options.ConnectionString);
199199
await conn.ExecuteAsync(
200-
$@"INSERT IGNORE INTO {_spiderId}_queue (hash, request) SELECT hash, request FROM {_spiderId}_set where state = 'P'");
200+
$@"INSERT IGNORE INTO `{_spiderId}_queue` (hash, request) SELECT hash, request FROM `{_spiderId}_set` where state = 'P'");
201201
}
202202

203203
public async Task SuccessAsync(Request request)

0 commit comments

Comments
 (0)