Skip to content

Commit 9af89d1

Browse files
committed
修复错误 & 调整编译脚本
1 parent d321d23 commit 9af89d1

File tree

8 files changed

+27
-25
lines changed

8 files changed

+27
-25
lines changed

build_agent.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
dotnet publish -c Release
22
cp -r src/DotnetSpider.Agent/bin/Release/netcoreapp3.1/publish/ dockerfile/agent/out
3-
cd dockerfile/agent
3+
cd dockerfile/agent || exit
44
docker build -t dotnetspider/agent:latest .

build_portal.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
cd src/DotnetSpider.Portal & yarn install
1+
cd src/DotnetSpider.Portal && yarn install
22
dotnet publish -c Release
3+
cd ../.. || exit
34
cp -r src/DotnetSpider.Portal/bin/Release/netcoreapp3.1/publish/ dockerfile/portal/out
4-
cd dockerfile/portal
5+
cd dockerfile/portal || exit
56
docker build -t dotnetspider/portal:latest .

build_spiders.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
dotnet publish -c Release
22
cp -r src/DotnetSpider.Spiders/bin/Release/netcoreapp3.1/publish/ dockerfile/spiders/out
3-
cd dockerfile/spiders
3+
cd dockerfile/spiders || exit
44
docker build -t dotnetspider/spiders:latest .

package.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
55
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
66
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
7-
<Version>5.0.0-beta2</Version>
7+
<Version>5.0.0-beta3</Version>
88
<FileVersion>5.0.0.1</FileVersion>
99
<Authors>[email protected];</Authors>
1010
<Copyright>Copyright 2018 Lewis Zou</Copyright>

src/DotnetSpider.Portal/Views/Agent/Index.cshtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</thead>
2828
<tbody>
2929
<tr v-if="items.length===0">
30-
<td colspan="7">None</td>
30+
<td colspan="8">None</td>
3131
</tr>
3232
<tr :id="item.id" v-else v-for="item in items">
3333
<td v-if="item.online" class="badge-success"></td>

src/DotnetSpider.Portal/Views/Spider/Index.cshtml

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
<th>CRON</th>
4646
<th>TYPE</th>
4747
<th>ENVIONMENT</th>
48-
<th>MODIFICATION TIME</th>
49-
<th style="width: 275px">ACTION</th>
48+
<th>EDIT TIME</th>
49+
<th style="width: 360px">ACTION</th>
5050
</tr>
5151
</thead>
5252
<tbody>
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"ConnectionString": "Database='dotnetspider2';Data Source=192.168.124.200;password=1qazZAQ!;User ID=root;Port=3306;",
2+
"ConnectionString": "Database='dotnetspider2';Data Source=localhost;password=1qazZAQ!;User ID=root;Port=3306;",
33
"DatabaseType": "MySql",
44
"RabbitMQ": {
55
"Exchange": "DOTNET_SPIDER",
6-
"Host": "192.168.124.200",
6+
"Host": "localhost",
77
"UserName": "user",
88
"Password": "password"
99
},
1010
"Database": "dotnetspider2",
11-
"Docker": "http://192.168.124.200:2376",
11+
"Docker": "http://192.168.1.105:2376",
1212
"DockerVolumes": ""
1313
}

src/DotnetSpider/Spider.cs

+15-14
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ public abstract partial class Spider :
2929
{
3030
private readonly List<IDataFlow> _dataFlows;
3131
private readonly List<IRequestSupplier> _requestSuppliers;
32-
private readonly SpiderOptions _options;
3332
private readonly RequestedQueue _requestedQueue;
3433
private AsyncMessageConsumer<byte[]> _consumer;
3534
private readonly SpiderServices _services;
3635

36+
protected SpiderOptions Options { get; private set; }
37+
3738
/// <summary>
3839
/// 爬虫标识
3940
/// </summary>
@@ -53,8 +54,8 @@ ILogger<Spider> logger
5354
{
5455
Logger = logger;
5556
_services = services;
56-
_options = options.Value;
57-
_requestedQueue = new RequestedQueue(_options);
57+
Options = options.Value;
58+
_requestedQueue = new RequestedQueue(Options);
5859
_requestSuppliers = new List<IRequestSupplier>();
5960
_dataFlows = new List<IDataFlow>();
6061
}
@@ -80,15 +81,15 @@ protected virtual (string Id, string Name) GetIdAndName()
8081

8182
protected IDataFlow GetDefaultStorage()
8283
{
83-
if (string.IsNullOrWhiteSpace(_options.Storage))
84+
if (string.IsNullOrWhiteSpace(Options.Storage))
8485
{
8586
throw new ArgumentNullException($"Storage is not configured");
8687
}
8788

88-
var type = Type.GetType(_options.Storage);
89+
var type = Type.GetType(Options.Storage);
8990
if (type == null)
9091
{
91-
throw new SpiderException($"Type of storage {_options.Storage} not found");
92+
throw new SpiderException($"Type of storage {Options.Storage} not found");
9293
}
9394

9495
if (!typeof(StorageBase).IsAssignableFrom(type) && !typeof(EntityStorageBase).IsAssignableFrom(type))
@@ -103,7 +104,7 @@ protected IDataFlow GetDefaultStorage()
103104
throw new SpiderException($"Storage {type} didn't implement method CreateFromOptions");
104105
}
105106

106-
var storage = method.Invoke(null, new object[] {_options});
107+
var storage = method.Invoke(null, new object[] {Options});
107108
if (storage == null)
108109
{
109110
throw new SpiderException("Create default storage failed");
@@ -186,15 +187,15 @@ protected async Task<int> AddRequestsAsync(IEnumerable<Request> requests)
186187

187188
// 1. 请求次数超过限制则跳过,并添加失败记录
188189
// 2. 默认构造的请求次数为 0, 并且不可用户更改,因此可以保证数据安全性
189-
if (request.RequestedTimes > _options.RetriedTimes)
190+
if (request.RequestedTimes > Options.RetriedTimes)
190191
{
191192
await _services.StatisticsClient.IncreaseFailureAsync(Id);
192193
continue;
193194
}
194195

195196
// 1. 默认构造的深度为 0, 并且用户不可更改,可以保证数据安全
196197
// 2. 当深度超过限制则跳过
197-
if (_options.Depth > 0 && request.Depth > _options.Depth)
198+
if (Options.Depth > 0 && request.Depth > Options.Depth)
198199
{
199200
continue;
200201
}
@@ -295,7 +296,7 @@ private async Task HandleResponseAsync(Request request, Response response, byte[
295296
try
296297
{
297298
using var scope = _services.ServiceProvider.CreateScope();
298-
var context = new DataContext(scope.ServiceProvider, _options, request, response);
299+
var context = new DataContext(scope.ServiceProvider, Options, request, response);
299300
context.AddData(Consts.ResponseBytes, responseBytes);
300301

301302
foreach (var dataFlow in _dataFlows)
@@ -318,8 +319,8 @@ private async Task HandleResponseAsync(Request request, Response response, byte[
318319

319320
private async Task RunAsync(CancellationToken stoppingToken)
320321
{
321-
var tuple = ComputeIntervalAndDequeueBatch(_options.Speed);
322-
var sleepTimeLimit = _options.EmptySleepTime * 1000;
322+
var tuple = ComputeIntervalAndDequeueBatch(Options.Speed);
323+
var sleepTimeLimit = Options.EmptySleepTime * 1000;
323324

324325
await Task.Factory.StartNew(async () =>
325326
{
@@ -337,7 +338,7 @@ await Task.Factory.StartNew(async () =>
337338
await _services.StatisticsClient.PrintAsync(Id);
338339
}
339340

340-
if (_requestedQueue.Count > _options.RequestedQueueCount)
341+
if (_requestedQueue.Count > Options.RequestedQueueCount)
341342
{
342343
if (pausedTime > sleepTimeLimit)
343344
{
@@ -434,7 +435,7 @@ private async Task<bool> PublishRequestMessagesAsync(params Request[] requests)
434435
{
435436
foreach (var request in requests)
436437
{
437-
if (_options.UseProxy)
438+
if (Options.UseProxy)
438439
{
439440
var proxy = await _services.ProxyPool.GetAsync(70);
440441
if (proxy == null)

0 commit comments

Comments
 (0)