Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yysh5
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
data_server
yysh5
Commits
e0fe4d6c
Commit
e0fe4d6c
authored
Sep 03, 2020
by
何娜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调试ws
parent
ee00c36c
Pipeline
#27890
passed with stage
in 22 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
106 additions
and
4 deletions
+106
-4
task.js
app/controller/task.js
+106
-4
No files found.
app/controller/task.js
View file @
e0fe4d6c
...
...
@@ -93,10 +93,112 @@ class TaskController extends Controller {
// key: String(task_id) + data.data.orderId,
// value: { status: 'login', note: { message: 'login' } },
// });
//ctx.success({ errcode: 0, taskId: task_id });
//
ctx.success({ errcode: 0, taskId: task_id });
ctx
.
success
({
errcode
:
0
,
data
:
{
task_id
}
});
}
async
wslink
()
{
const
{
ctx
,
service
}
=
this
;
console
.
log
(
'【wslink】ctx---'
,
ctx
);
const
{
ws
}
=
ctx
.
ws
;
const
{
orderId
,
taskId
,
appKey
,
netMark
,
type
}
=
ctx
.
query
;
if
(
!
orderId
)
{
return
;
}
if
(
type
===
'query'
)
{
const
order
=
await
service
.
order
.
getOneByParams
({
orderId
,
taskId
});
const
status
=
order
.
status
;
ctx
.
app
.
wsMap
.
set
(
String
(
taskId
)
+
orderId
,
{
ws
,
addTime
:
new
Date
().
getTime
()
});
ctx
.
app
.
orderIdMap
.
set
(
String
(
taskId
)
+
orderId
,
{
orderSn
:
orderId
,
addTime
:
new
Date
().
getTime
(),
type
:
'ws'
,
state
:
'open'
,
appKey
,
netMark
,
});
try
{
ws
.
send
(
'ok'
);
}
catch
(
err
)
{
console
.
log
(
'[err ws send ok]'
);
}
if
(
status
===
'failed'
)
{
ws
.
send
(
JSON
.
stringify
({
errcode
:
0
,
data
:
{
state
:
-
2
,
result
:
'任务失败,请稍后重试'
}
}));
}
else
if
(
status
===
'success'
)
{
ws
.
send
(
JSON
.
stringify
({
errcode
:
0
,
data
:
{
state
:
2
,
result
:
'success'
}
}));
}
else
{
const
result
=
await
service
.
task
.
fetchTask
({
taskId
});
let
data
,
wsMsg
;
switch
(
result
.
code
)
{
case
-
1
:
data
=
{
status
:
'failed'
,
note
:
JSON
.
stringify
({
code
:
106
,
message
:
'任务失败'
}),
};
wsMsg
=
{
errcode
:
0
,
data
:
{
state
:
-
2
,
result
:
'任务失败,请稍后重试'
}
};
case
0
:
if
(
new
Date
().
getTime
()
-
order
.
updated_at
>
15
*
60
*
1000
)
{
data
=
{
status
:
'failed'
,
note
:
JSON
.
stringify
({
code
:
106
,
message
:
'任务超时'
}),
};
wsMsg
=
{
errcode
:
0
,
data
:
{
state
:
-
2
,
result
:
'任务超时,请稍后重试'
}
};
}
}
service
.
order
.
update
(
data
,
{
orderId
,
taskId
});
ws
.
send
(
JSON
.
stringify
(
wsMsg
));
}
}
else
{
ctx
.
app
.
wsMap
.
set
(
String
(
taskId
)
+
orderId
,
{
ws
,
addTime
:
new
Date
().
getTime
()
});
ctx
.
app
.
orderIdMap
.
set
(
String
(
taskId
)
+
orderId
,
{
orderSn
:
orderId
,
addTime
:
new
Date
().
getTime
(),
type
:
'ws'
,
state
:
'open'
,
appKey
,
netMark
,
});
try
{
ws
.
send
(
'ok'
);
}
catch
(
err
)
{
console
.
log
(
'[err ws send ok]'
);
}
let
result
=
await
this
.
handleCallback
();
if
(
result
.
errcode
!==
2
)
{
if
(
ctx
.
app
.
wsMap
.
has
(
String
(
taskId
)
+
orderId
))
{
result
=
JSON
.
stringify
(
result
);
try
{
ctx
.
app
.
wsMap
.
get
(
String
(
taskId
)
+
orderId
).
ws
.
send
(
result
);
}
catch
(
err
)
{
console
.
error
(
'[send Err]'
);
}
}
else
{
result
.
addTime
=
new
Date
().
getTime
();
ctx
.
app
.
noWsMap
.
set
(
String
(
taskId
)
+
orderId
,
result
);
}
}
else
{
console
.
log
(
result
);
}
}
ws
.
on
(
'message'
,
function
(
msg
)
{
// 暂未有用户主动请求情况
console
.
log
(
msg
);
});
ws
.
on
(
'close'
,
function
()
{
// console.log('[thxd]ws连接断开');
if
(
ctx
.
app
.
wsMap
.
has
(
String
(
taskId
)
+
orderId
))
{
ctx
.
app
.
wsMap
.
delete
(
String
(
taskId
)
+
orderId
);
if
(
ctx
.
app
.
orderIdMap
.
has
(
String
(
taskId
)
+
orderId
))
{
// console.log('[thxd]修改当前ws为close状态 orderSn: ' + orderIdMap.get(String(req.query.taskId)).orderSn);
ctx
.
app
.
orderIdMap
.
get
(
String
(
taskId
)
+
orderId
).
state
=
'close'
;
}
// console.log('[thxd]ws连接断开');
}
});
}
async
fetchCapture
()
{
const
{
ctx
,
service
}
=
this
;
const
{
args
,
task_id
}
=
ctx
.
request
.
body
;
...
...
@@ -111,10 +213,10 @@ class TaskController extends Controller {
const
{
ctx
,
service
}
=
this
;
const
{
cid
}
=
ctx
.
request
.
body
;
const
data
=
ctx
.
app
.
cityMap
.
get
(
cid
)
||
{};
let
formHtml
=
await
service
.
index
.
getCityHtml
(
data
.
queryStepParam
[
0
].
loginParam
,
cid
,
{
name
:
''
,
ID
:
''
,
password
:
''
});
let
formHtml
=
await
service
.
index
.
getCityHtml
(
data
.
queryStepParam
[
0
].
loginParam
,
cid
,
{
name
:
''
,
ID
:
''
,
password
:
''
});
if
(
data
.
state
!==
1
)
{
formHtml
=
await
service
.
index
.
getCityHtml
(
data
.
queryStepParam
[
0
].
loginParam
,
cid
,
{
name
:
''
,
ID
:
''
,
password
:
''
});
formHtml
=
await
service
.
index
.
getCityHtml
(
data
.
queryStepParam
[
0
].
loginParam
,
cid
,
{
name
:
''
,
ID
:
''
,
password
:
''
});
}
ctx
.
success
(
formHtml
);
}
...
...
@@ -141,7 +243,7 @@ class TaskController extends Controller {
switch
(
result
.
code
)
{
case
-
1
:
service
.
order
.
update
({
status
:
'fail'
,
status
:
'fail
ed
'
,
note
:
result
,
},
{
orderId
,
taskId
});
ctx
.
success
({
errcode
:
1
,
data
:
{
state
:
-
1
,
result
:
'服务器出错,请稍后重试'
}
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment