Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
Nestjs Aragami
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
3rdeye
Nestjs Aragami
Commits
965f6b03
Commit
965f6b03
authored
Jun 05, 2023
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add QueueRunner
parent
7927e453
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
105 additions
and
8 deletions
+105
-8
package-lock.json
package-lock.json
+24
-7
package.json
package.json
+1
-1
src/queue-runner.ts
src/queue-runner.ts
+80
-0
No files found.
package-lock.json
View file @
965f6b03
...
...
@@ -25,7 +25,7 @@
"peerDependencies"
:
{
"@nestjs/common"
:
"^9.1.2"
,
"@nestjs/core"
:
"^9.4.2"
,
"aragami"
:
"^1.1.
2
"
,
"aragami"
:
"^1.1.
8
"
,
"rxjs"
:
"^7.8.1"
}
},
...
...
@@ -1653,15 +1653,16 @@
}
},
"node_modules/aragami"
:
{
"version"
:
"1.1.
2
"
,
"resolved"
:
"https://registry.npmjs.org/aragami/-/aragami-1.1.
2
.tgz"
,
"integrity"
:
"sha512-
asrmtKkLOgtXMYt3TeM/lWsmbKdJwjUPDV9yb+h62FBBMFx0h+lrEQN1XL6ZIkfyggtyC0G5gv0f9G+Ul0cTU
g=="
,
"version"
:
"1.1.
8
"
,
"resolved"
:
"https://registry.npmjs.org/aragami/-/aragami-1.1.
8
.tgz"
,
"integrity"
:
"sha512-
kHwOawwEFfEyxAt6/dRm5YORgIfFtZl2b/TFoZx0LxQzP3uqNgf1tkbfjLEVi5DI+nRAe6iDd+43bn1c5ZNXC
g=="
,
"peer"
:
true
,
"dependencies"
:
{
"@nanahira/redlock"
:
"^1.0.0"
,
"better-lock"
:
"^2.0.3"
,
"class-transformer"
:
"^0.5.1"
,
"encoded-buffer"
:
"^0.2.6"
,
"generic-pool"
:
"^3.9.0"
,
"ioredis"
:
"^5.2.3"
,
"lodash"
:
"^4.17.21"
,
"lru-cache"
:
"^7.13.1"
,
...
...
@@ -2671,6 +2672,15 @@
"integrity"
:
"sha512-dsKNQNdj6xA3T+QlADDA7mOSlX0qiMINjn0cgr+eGHGsbSHzTabcIogz2+p/iqP1Xs6EP/sS2SbqH+brGTbq0g=="
,
"dev"
:
true
},
"node_modules/generic-pool"
:
{
"version"
:
"3.9.0"
,
"resolved"
:
"https://registry.npmjs.org/generic-pool/-/generic-pool-3.9.0.tgz"
,
"integrity"
:
"sha512-hymDOu5B53XvN4QT9dBmZxPX4CWhBPPLguTZ9MMFeFa/Kg0xWVfylOVNlJji/E7yTZWFd/q9GO5TxDLq156D7g=="
,
"peer"
:
true
,
"engines"
:
{
"node"
:
">= 4"
}
},
"node_modules/gensync"
:
{
"version"
:
"1.0.0-beta.2"
,
"resolved"
:
"https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz"
,
...
...
@@ -6369,15 +6379,16 @@
}
},
"aragami"
:
{
"version"
:
"1.1.
2
"
,
"resolved"
:
"https://registry.npmjs.org/aragami/-/aragami-1.1.
2
.tgz"
,
"integrity"
:
"sha512-
asrmtKkLOgtXMYt3TeM/lWsmbKdJwjUPDV9yb+h62FBBMFx0h+lrEQN1XL6ZIkfyggtyC0G5gv0f9G+Ul0cTU
g=="
,
"version"
:
"1.1.
8
"
,
"resolved"
:
"https://registry.npmjs.org/aragami/-/aragami-1.1.
8
.tgz"
,
"integrity"
:
"sha512-
kHwOawwEFfEyxAt6/dRm5YORgIfFtZl2b/TFoZx0LxQzP3uqNgf1tkbfjLEVi5DI+nRAe6iDd+43bn1c5ZNXC
g=="
,
"peer"
:
true
,
"requires"
:
{
"@nanahira/redlock"
:
"^1.0.0"
,
"better-lock"
:
"^2.0.3"
,
"class-transformer"
:
"^0.5.1"
,
"encoded-buffer"
:
"^0.2.6"
,
"generic-pool"
:
"^3.9.0"
,
"ioredis"
:
"^5.2.3"
,
"lodash"
:
"^4.17.21"
,
"lru-cache"
:
"^7.13.1"
,
...
...
@@ -7147,6 +7158,12 @@
"integrity"
:
"sha512-dsKNQNdj6xA3T+QlADDA7mOSlX0qiMINjn0cgr+eGHGsbSHzTabcIogz2+p/iqP1Xs6EP/sS2SbqH+brGTbq0g=="
,
"dev"
:
true
},
"generic-pool"
:
{
"version"
:
"3.9.0"
,
"resolved"
:
"https://registry.npmjs.org/generic-pool/-/generic-pool-3.9.0.tgz"
,
"integrity"
:
"sha512-hymDOu5B53XvN4QT9dBmZxPX4CWhBPPLguTZ9MMFeFa/Kg0xWVfylOVNlJji/E7yTZWFd/q9GO5TxDLq156D7g=="
,
"peer"
:
true
},
"gensync"
:
{
"version"
:
"1.0.0-beta.2"
,
"resolved"
:
"https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz"
,
...
...
package.json
View file @
965f6b03
...
...
@@ -55,7 +55,7 @@
"peerDependencies"
:
{
"@nestjs/common"
:
"^9.1.2"
,
"@nestjs/core"
:
"^9.4.2"
,
"aragami"
:
"^1.1.
2
"
,
"aragami"
:
"^1.1.
8
"
,
"rxjs"
:
"^7.8.1"
}
}
src/queue-runner.ts
0 → 100644
View file @
965f6b03
import
{
Aragami
,
ClassType
}
from
'
aragami
'
;
import
{
Logger
}
from
'
@nestjs/common
'
;
import
*
as
os
from
'
os
'
;
import
{
InjectAragami
}
from
'
../index
'
;
export
interface
QueueRunnerOptions
{
maxConcurrency
?:
number
;
key
?:
string
;
logTask
?:
boolean
;
}
export
class
_QueueRunner
<
T
>
{
logger
=
new
Logger
(
this
.
_queueClass
.
name
);
_maxConcurrency
=
this
.
_queueRunnerOptions
.
maxConcurrency
??
os
.
cpus
().
length
;
constructor
(
public
_queueClass
:
ClassType
<
T
>
,
public
_queueRunnerOptions
:
QueueRunnerOptions
,
)
{}
@
InjectAragami
()
aragami
:
Aragami
;
async
onApplicationBootstrap
()
{
if
(
this
.
_queueRunnerOptions
.
logTask
)
{
this
.
logger
.
log
(
`Starting
${
this
.
_maxConcurrency
}
workers`
);
}
for
(
let
i
=
0
;
i
<
this
.
_maxConcurrency
;
i
++
)
{
if
(
this
.
_queueRunnerOptions
.
logTask
)
{
this
.
logger
.
log
(
`Starting worker
${
i
}
`
);
}
this
.
_mainLoop
().
then
();
}
}
_quit
=
false
;
async
onApplicationShutdown
()
{
this
.
_quit
=
true
;
}
async
runTask
(
task
:
T
)
{
return
;
}
async
_mainLoop
()
{
while
(
!
this
.
_quit
)
{
this
.
logger
.
log
(
'
Looping
'
);
try
{
const
task
:
T
=
await
this
.
aragami
.
queueGatherBlocking
(
this
.
_queueClass
,
this
.
_queueRunnerOptions
.
key
||
'
default
'
,
);
if
(
!
task
)
continue
;
if
(
this
.
_queueRunnerOptions
.
logTask
)
{
this
.
logger
.
log
(
`Got task:
${
JSON
.
stringify
(
task
)}
`
);
}
await
this
.
runTask
(
task
);
}
catch
(
e
)
{
this
.
logger
.
error
(
`Loop failed:
${
e
}
`
);
}
}
}
}
export
function
QueueRunner
<
T
>
(
queueClass
:
ClassType
<
T
>
,
options
?:
Partial
<
QueueRunnerOptions
>
,
)
{
const
cl
=
class
extends
_QueueRunner
<
T
>
{
constructor
(
innerOptions
?:
Partial
<
QueueRunnerOptions
>
)
{
super
(
queueClass
,
{
...(
innerOptions
||
{}),
...(
options
||
{}),
});
}
};
Object
.
defineProperty
(
cl
,
'
name
'
,
{
value
:
queueClass
.
name
+
'
Runner
'
});
return
cl
;
}
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