-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
236 lines (203 loc) · 4.76 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
package gui
import (
"strconv"
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
"github.com/henrylee2cn/pholcus/app"
"github.com/henrylee2cn/pholcus/config"
"github.com/henrylee2cn/pholcus/logs"
)
var serverCount int
func serverWindow() {
mw.Close()
if err := (MainWindow{
AssignTo: &mw,
DataBinder: DataBinder{
AssignTo: &db,
DataSource: Input,
ErrorPresenter: ErrorPresenterRef{&ep},
},
Title: config.FULL_NAME + " 【 运行模式 -> 服务器 】",
MinSize: Size{1100, 700},
Layout: VBox{MarginsZero: true},
Children: []Widget{
Composite{
AssignTo: &setting,
Layout: Grid{Columns: 2},
Children: []Widget{
// 任务列表
TableView{
ColumnSpan: 1,
MinSize: Size{550, 450},
AlternatingRowBGColor: walk.RGB(255, 255, 224),
CheckBoxes: true,
ColumnsOrderable: true,
Columns: []TableViewColumn{
{Title: "#", Width: 45},
{Title: "任务", Width: 110 /*, Format: "%.2f", Alignment: AlignFar*/},
{Title: "描述", Width: 370},
},
Model: spiderMenu,
},
VSplitter{
ColumnSpan: 1,
MinSize: Size{550, 450},
Children: []Widget{
VSplitter{
Children: []Widget{
Label{
Text: "自定义配置(多任务请分别多包一层“<>”)",
},
LineEdit{
Text: Bind("Keyins"),
},
},
},
VSplitter{
Children: []Widget{
Label{
Text: "*采集上限(默认限制URL数):",
},
NumberEdit{
Value: Bind("Limit"),
Suffix: "",
Decimals: 0,
},
},
},
VSplitter{
Children: []Widget{
Label{
Text: "*并发协程:(1~99999)",
},
NumberEdit{
Value: Bind("ThreadNum", Range{1, 99999}),
Suffix: "",
Decimals: 0,
},
},
},
VSplitter{
Children: []Widget{
Label{
Text: "*分批输出大小:(1~5,000,000 条数据)",
},
NumberEdit{
Value: Bind("DockerCap", Range{1, 5000000}),
Suffix: "",
Decimals: 0,
},
},
},
VSplitter{
Children: []Widget{
Label{
Text: "*暂停时长参考:",
},
ComboBox{
Value: Bind("Pausetime", SelRequired{}),
DisplayMember: "Key",
BindingMember: "Int64",
Model: GuiOpt.Pausetime,
},
},
},
VSplitter{
Children: []Widget{
Label{
Text: "*代理IP更换频率:",
},
ComboBox{
Value: Bind("ProxyMinute", SelRequired{}),
DisplayMember: "Key",
BindingMember: "Int64",
Model: GuiOpt.ProxyMinute,
},
},
},
RadioButtonGroupBox{
ColumnSpan: 1,
Title: "*输出方式",
Layout: HBox{},
DataMember: "OutType",
Buttons: outputList,
},
},
},
},
},
Composite{
Layout: HBox{},
Children: []Widget{
// 必填项错误检查
LineErrorPresenter{
AssignTo: &ep,
},
HSplitter{
MaxSize: Size{220, 50},
Children: []Widget{
Label{
Text: "继承并保存成功记录",
},
CheckBox{
Checked: Bind("SuccessInherit"),
},
},
},
HSplitter{
MaxSize: Size{220, 50},
Children: []Widget{
Label{
Text: "继承并保存失败记录",
},
CheckBox{
Checked: Bind("FailureInherit"),
},
},
},
PushButton{
MinSize: Size{90, 0},
Text: serverBtnTxt(),
AssignTo: &runStopBtn,
OnClicked: serverStart,
},
},
},
},
}.Create()); err != nil {
panic(err)
}
setWindow()
// 初始化应用
Init()
// 运行窗体程序
mw.Run()
}
// 点击开始事件
func serverStart() {
if err := db.Submit(); err != nil {
logs.Log.Error("%v", err)
return
}
// 读取任务
Input.Spiders = spiderMenu.GetChecked()
if len(Input.Spiders) == 0 {
logs.Log.Warning(" * —— 亲,任务列表不能为空哦~")
return
}
// 记录配置信息
SetTaskConf()
runStopBtn.SetEnabled(false)
runStopBtn.SetText("分发任务 (···)")
// 重置spiders队列
SpiderPrepare()
// 生成分发任务
app.LogicApp.Run()
serverCount++
runStopBtn.SetText(serverBtnTxt())
runStopBtn.SetEnabled(true)
}
// 更新按钮文字
func serverBtnTxt() string {
return "分发任务 (" + strconv.Itoa(serverCount) + ")"
}