Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
console
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
console
Commits
3f7750af
Commit
3f7750af
authored
Nov 30, 2023
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use redlock autoquit
parent
eb9d33d1
Pipeline
#24199
passed with stages
in 4 minutes and 35 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
21 deletions
+34
-21
console-api/package-lock.json
console-api/package-lock.json
+0
-11
console-api/package.json
console-api/package.json
+0
-1
console-api/src/lock/lock.service.ts
console-api/src/lock/lock.service.ts
+32
-4
console-api/src/mirror/mirror.service.ts
console-api/src/mirror/mirror.service.ts
+1
-1
console-api/src/packager/packager.service.ts
console-api/src/packager/packager.service.ts
+1
-4
No files found.
console-api/package-lock.json
View file @
3f7750af
...
...
@@ -23,7 +23,6 @@
"@nestjs/swagger"
:
"^5.0.9"
,
"@nestjs/typeorm"
:
"^8.0.2"
,
"axios"
:
"^0.21.1"
,
"better-lock"
:
"^2.0.3"
,
"busboy"
:
"^0.2.14"
,
"class-transformer"
:
"^0.4.0"
,
"class-validator"
:
"^0.13.1"
,
...
...
@@ -4203,11 +4202,6 @@
}
]
},
"node_modules/better-lock"
:
{
"version"
:
"2.0.3"
,
"resolved"
:
"https://registry.npmjs.org/better-lock/-/better-lock-2.0.3.tgz"
,
"integrity"
:
"sha512-3bCaToLrmEXZcIOOVWgi1STvp3/6EpoZAmlWBeuX2MvDB0Ql2ctl/vQ0CbhQIJYQiptdGypllP3ez+TeEmdnKQ=="
},
"node_modules/binary-extensions"
:
{
"version"
:
"2.2.0"
,
"resolved"
:
"https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz"
,
...
...
@@ -15213,11 +15207,6 @@
"resolved"
:
"https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz"
,
"integrity"
:
"sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA=="
},
"better-lock"
:
{
"version"
:
"2.0.3"
,
"resolved"
:
"https://registry.npmjs.org/better-lock/-/better-lock-2.0.3.tgz"
,
"integrity"
:
"sha512-3bCaToLrmEXZcIOOVWgi1STvp3/6EpoZAmlWBeuX2MvDB0Ql2ctl/vQ0CbhQIJYQiptdGypllP3ez+TeEmdnKQ=="
},
"binary-extensions"
:
{
"version"
:
"2.2.0"
,
"resolved"
:
"https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz"
,
...
...
console-api/package.json
View file @
3f7750af
...
...
@@ -35,7 +35,6 @@
"@nestjs/swagger"
:
"^5.0.9"
,
"@nestjs/typeorm"
:
"^8.0.2"
,
"axios"
:
"^0.21.1"
,
"better-lock"
:
"^2.0.3"
,
"busboy"
:
"^0.2.14"
,
"class-transformer"
:
"^0.4.0"
,
"class-validator"
:
"^0.13.1"
,
...
...
console-api/src/lock/lock.service.ts
View file @
3f7750af
...
...
@@ -5,11 +5,39 @@ import Redis from 'ioredis';
@
Injectable
()
export
class
LockService
{
constructor
(
private
config
:
ConfigService
)
{
}
getLockInstance
()
{
constructor
(
private
config
:
ConfigService
)
{}
createRedisClient
()
{
const
url
=
this
.
config
.
get
<
string
>
(
'
REDIS_URL
'
);
const
redis
=
new
Redis
(
url
);
return
new
Redis
(
url
);
}
getLockInstance
()
{
const
redis
=
this
.
createRedisClient
();
return
new
Redlock
([
redis
]);
}
async
useTmpRedisClient
<
T
>
(
cb
:
(
redis
:
Redis
.
Redis
)
=>
Promise
<
T
>
)
{
const
redis
=
this
.
createRedisClient
();
try
{
return
await
cb
(
redis
);
}
finally
{
await
redis
.
quit
();
}
}
async
useTmpLockInstance
<
T
>
(
cb
:
(
lock
:
Redlock
)
=>
Promise
<
T
>
)
{
const
lock
=
this
.
getLockInstance
();
try
{
return
await
cb
(
lock
);
}
finally
{
await
lock
.
quit
();
}
}
async
using
<
T
>
(
key
:
string
[],
timeout
:
number
,
cb
:
()
=>
Promise
<
T
>
)
{
return
this
.
useTmpLockInstance
(
async
(
lock
)
=>
{
return
await
lock
.
using
(
key
,
timeout
,
cb
);
});
}
}
console-api/src/mirror/mirror.service.ts
View file @
3f7750af
...
...
@@ -185,7 +185,7 @@ export class MirrorService extends ConsoleLogger implements OnApplicationBootstr
if
(
!
middleware
.
singleton
)
{
return
this
.
uploadWithMiddlewareProcess
(
uploadInfo
,
middleware
);
}
return
this
.
redlock
.
getLockInstance
().
using
([
`mirror:
${
middleware
.
identifier
}
`
],
5000
,
()
=>
this
.
uploadWithMiddlewareProcess
(
uploadInfo
,
middleware
));
return
this
.
redlock
.
using
([
`mirror:
${
middleware
.
identifier
}
`
],
5000
,
()
=>
this
.
uploadWithMiddlewareProcess
(
uploadInfo
,
middleware
));
}
async
uploadWithRandomMiddleware
(
uploadInfo
:
UploadInfo
,
middlewares
=
Array
.
from
(
this
.
middlewares
.
values
()))
{
...
...
console-api/src/packager/packager.service.ts
View file @
3f7750af
...
...
@@ -17,7 +17,6 @@ import { createHash } from 'crypto';
import
PQueue
from
'
p-queue
'
;
import
{
LockService
}
from
'
src/lock/lock.service
'
;
import
{
InjectRedis
,
Redis
}
from
'
@nestjs-modules/ioredis
'
;
import
BetterLock
from
'
better-lock
'
;
interface
FileWithHash
{
file
:
readdirp
.
EntryInfo
;
...
...
@@ -209,10 +208,8 @@ export class PackagerService extends ConsoleLogger {
]);
}
private
localLock
=
new
BetterLock
();
async
archive
(
root
:
string
,
archiveTask
:
ArchiveTask
):
Promise
<
Archive
>
{
return
this
.
localLock
.
acquire
([
`archive:
${
archiveTask
.
path
}
`
]
,
async
()
=>
this
.
archiveProcess
(
root
,
archiveTask
));
return
this
.
redlock
.
using
([
`archive:
${
archiveTask
.
path
}
`
],
30000
,
async
()
=>
this
.
archiveProcess
(
root
,
archiveTask
));
}
private
archiveQueue
=
new
PQueue
({
concurrency
:
parseInt
(
process
.
env
.
PACKAGE_COCURRENCY
)
||
os
.
cpus
().
length
});
...
...
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