Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taobao-mini-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
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
qinhaitao
taobao-mini-template
Commits
a6d6a813
Commit
a6d6a813
authored
Aug 13, 2020
by
汪忙忙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: lockUpdate
parent
3d57e543
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
4 deletions
+12
-4
lockUpdate.js
v1.0/utils/package/lockUpdate.js
+12
-4
No files found.
v1.0/utils/package/lockUpdate.js
View file @
a6d6a813
const
{
CODE_TYPES
}
=
require
(
'../../constants'
);
const
{
CODE_TYPES
}
=
require
(
'../../constants'
);
/**
/**
* 并发更新
* 并发更新
* @param {接收数组或对象} daoqueryArr : [{dao: userdao, query:{
id:_id}}, {dao: activityprizedao, query: {id:_id
}}]
* @param {接收数组或对象} daoqueryArr : [{dao: userdao, query:{
_id:_id}}, {dao: activityprizedao, query: {userNick, status ...
}}]
* @param {*} fn
* @param {*} fn
* @param {*} times
* @param {*} times
*/
*/
...
@@ -10,7 +10,7 @@ const lockUpdate = async(daoqueryArr, fn, times=5) => {
...
@@ -10,7 +10,7 @@ const lockUpdate = async(daoqueryArr, fn, times=5) => {
console
.
log
(
`lockUpdate 参数错误`
);
console
.
log
(
`lockUpdate 参数错误`
);
return
false
;
return
false
;
}
}
if
(
daoqueryArr
instanceof
Object
)
{
if
(
!
daoqueryArr
instanceof
Array
)
{
daoqueryArr
=
[
daoqueryArr
];
daoqueryArr
=
[
daoqueryArr
];
}
}
let
time
=
0
;
let
time
=
0
;
...
@@ -26,8 +26,10 @@ const lockUpdate = async(daoqueryArr, fn, times=5) => {
...
@@ -26,8 +26,10 @@ const lockUpdate = async(daoqueryArr, fn, times=5) => {
if
(
!
daoquery
.
dao
||
!
daoquery
.
query
)
{
if
(
!
daoquery
.
dao
||
!
daoquery
.
query
)
{
success
=
true
;
success
=
true
;
error
=
true
error
=
true
console
.
log
(
`daoquery`
,
daoquery
)
break
break
}
else
{
}
else
{
console
.
log
(
`daoquery`
,
daoquery
)
let
canupdate
=
await
daoquery
.
dao
.
update
(
daoquery
.
query
,
{
$set
:
{
lockStatus
:
2
}});
let
canupdate
=
await
daoquery
.
dao
.
update
(
daoquery
.
query
,
{
$set
:
{
lockStatus
:
2
}});
updateRes
.
push
(
canupdate
);
updateRes
.
push
(
canupdate
);
}
}
...
@@ -35,10 +37,13 @@ const lockUpdate = async(daoqueryArr, fn, times=5) => {
...
@@ -35,10 +37,13 @@ const lockUpdate = async(daoqueryArr, fn, times=5) => {
if
(
error
)
{
if
(
error
)
{
return
`调用lockUpdate方法参数不符合规范`
return
`调用lockUpdate方法参数不符合规范`
}
}
console
.
log
(
`updateRes`
,
updateRes
)
// 若都锁定成功了,执行内部调用
// 若都锁定成功了,执行内部调用
if
(
!
daoqueryArr
.
includes
(
0
))
{
if
(
updateRes
.
every
((
v
)
=>
v
===
1
))
{
const
ret
=
await
fn
();
const
ret
=
await
fn
();
console
.
log
(
`完成调用,解锁操作执行--------------`
);
daoqueryArr
.
forEach
(
async
daoquery
=>
{
daoqueryArr
.
forEach
(
async
daoquery
=>
{
console
.
log
(
daoquery
)
let
ures
=
await
daoquery
.
dao
.
update
(
daoquery
.
query
,
{
$set
:
{
lockStatus
:
1
}});
let
ures
=
await
daoquery
.
dao
.
update
(
daoquery
.
query
,
{
$set
:
{
lockStatus
:
1
}});
console
.
log
(
`更新lockStatus为1`
,
ures
);
console
.
log
(
`更新lockStatus为1`
,
ures
);
});
});
...
@@ -54,13 +59,15 @@ const lockUpdate = async(daoqueryArr, fn, times=5) => {
...
@@ -54,13 +59,15 @@ const lockUpdate = async(daoqueryArr, fn, times=5) => {
console
.
log
(
e
);
console
.
log
(
e
);
daoqueryArr
.
forEach
(
async
daoquery
=>
{
daoqueryArr
.
forEach
(
async
daoquery
=>
{
let
ures
=
await
daoquery
.
dao
.
update
(
daoquery
.
query
,
{
$set
:
{
lockStatus
:
1
}});
let
ures
=
await
daoquery
.
dao
.
update
(
daoquery
.
query
,
{
$set
:
{
lockStatus
:
1
}});
console
.
log
(
`更新lockStatus为
0
`
,
ures
);
console
.
log
(
`更新lockStatus为
1
`
,
ures
);
});
});
success
=
false
;
success
=
false
;
}
}
console
.
log
(
`daoqueryArr`
,
daoqueryArr
)
// 稍后重试
// 稍后重试
if
(
!
success
)
{
if
(
!
success
)
{
daoqueryArr
.
forEach
(
async
daoquery
=>
{
daoqueryArr
.
forEach
(
async
daoquery
=>
{
console
.
log
(
daoquery
)
let
ures
=
await
daoquery
.
dao
.
update
(
daoquery
.
query
,
{
$set
:
{
lockStatus
:
1
}});
let
ures
=
await
daoquery
.
dao
.
update
(
daoquery
.
query
,
{
$set
:
{
lockStatus
:
1
}});
console
.
log
(
`操作
${
times
}
次后更新lockStatus为1`
,
ures
);
console
.
log
(
`操作
${
times
}
次后更新lockStatus为1`
,
ures
);
});
});
...
@@ -75,6 +82,7 @@ const lockUpdate = async(daoqueryArr, fn, times=5) => {
...
@@ -75,6 +82,7 @@ const lockUpdate = async(daoqueryArr, fn, times=5) => {
module
.
exports
=
lockUpdate
;
module
.
exports
=
lockUpdate
;
/**
/**
* 调用示例
* 调用示例
*/
*/
...
...
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