Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
exchain
nebula
Commits
8d1f346e
Unverified
Commit
8d1f346e
authored
Mar 11, 2022
by
smartcontracts
Committed by
GitHub
Mar 11, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2315 from ethereum-optimism/sc/base-service-mini-improvements
various small BaseServiceV2 improvements
parents
07538ec6
f7761058
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
9 deletions
+30
-9
good-knives-add.md
.changeset/good-knives-add.md
+5
-0
selfish-paws-reply.md
.changeset/selfish-paws-reply.md
+5
-0
base-service-v2.ts
packages/common-ts/src/base-service/base-service-v2.ts
+20
-9
No files found.
.changeset/good-knives-add.md
0 → 100644
View file @
8d1f346e
---
'
@eth-optimism/common-ts'
:
patch
---
Update log lines for service shutdown
.changeset/selfish-paws-reply.md
0 → 100644
View file @
8d1f346e
---
'
@eth-optimism/common-ts'
:
patch
---
Update metric names to include proper snake_case for strings that include "L1" or "L2"
packages/common-ts/src/base-service/base-service-v2.ts
View file @
8d1f346e
...
@@ -107,19 +107,28 @@ export abstract class BaseServiceV2<
...
@@ -107,19 +107,28 @@ export abstract class BaseServiceV2<
params
.
loopIntervalMs
!==
undefined
?
params
.
loopIntervalMs
:
0
params
.
loopIntervalMs
!==
undefined
?
params
.
loopIntervalMs
:
0
this
.
state
=
{}
as
TServiceState
this
.
state
=
{}
as
TServiceState
/**
* Special snake_case function which accounts for the common strings "L1" and "L2" which would
* normally be split into "L_1" and "L_2" by the snake_case function.
*
* @param str String to convert to snake_case.
* @returns snake_case string.
*/
const
opSnakeCase
=
(
str
:
string
)
=>
{
const
reg
=
/l_1|l_2/g
const
repl
=
str
.
includes
(
'
l1
'
)
?
'
l1
'
:
'
l2
'
return
snakeCase
(
str
).
replace
(
reg
,
repl
)
}
// Use commander as a way to communicate info about the service. We don't actually *use*
// Use commander as a way to communicate info about the service. We don't actually *use*
// commander for anything besides the ability to run `ts-node ./service.ts --help`.
// commander for anything besides the ability to run `ts-node ./service.ts --help`.
const
program
=
new
Command
()
const
program
=
new
Command
()
const
reg
=
/L_1|L_2/g
for
(
const
[
optionName
,
optionSpec
]
of
Object
.
entries
(
params
.
optionsSpec
))
{
for
(
const
[
optionName
,
optionSpec
]
of
Object
.
entries
(
params
.
optionsSpec
))
{
const
repl
=
optionName
.
includes
(
'
l1
'
)
?
'
L1
'
:
'
L2
'
program
.
addOption
(
program
.
addOption
(
new
Option
(
`--
${
optionName
.
toLowerCase
()}
`
,
`
${
optionSpec
.
desc
}
`
).
env
(
new
Option
(
`--
${
optionName
.
toLowerCase
()}
`
,
`
${
optionSpec
.
desc
}
`
).
env
(
`
${
s
nakeCase
(
`
${
opS
nakeCase
(
params
.
name
.
replace
(
/-/g
,
'
_
'
)
params
.
name
.
replace
(
/-/g
,
'
_
'
)
).
toUpperCase
()}
__
${
snakeCase
(
optionName
)
).
toUpperCase
()}
__
${
opSnakeCase
(
optionName
).
toUpperCase
()}
`
.
toUpperCase
()
.
replace
(
reg
,
repl
)}
`
)
)
)
)
}
}
...
@@ -140,7 +149,7 @@ export abstract class BaseServiceV2<
...
@@ -140,7 +149,7 @@ export abstract class BaseServiceV2<
'
after
'
,
'
after
'
,
`\nMetrics:\n
${
Object
.
entries
(
params
.
metricsSpec
)
`\nMetrics:\n
${
Object
.
entries
(
params
.
metricsSpec
)
.
map
(([
metricName
,
metricSpec
])
=>
{
.
map
(([
metricName
,
metricSpec
])
=>
{
const
parsedName
=
s
nakeCase
(
metricName
)
const
parsedName
=
opS
nakeCase
(
metricName
)
return
`
${
parsedName
}${
'
'
.
repeat
(
return
`
${
parsedName
}${
'
'
.
repeat
(
longestMetricNameLength
-
parsedName
.
length
+
2
longestMetricNameLength
-
parsedName
.
length
+
2
)}${
metricSpec
.
desc
}
(type:
${
metricSpec
.
type
.
name
}
)`
)}${
metricSpec
.
desc
}
(type:
${
metricSpec
.
type
.
name
}
)`
...
@@ -187,7 +196,7 @@ export abstract class BaseServiceV2<
...
@@ -187,7 +196,7 @@ export abstract class BaseServiceV2<
this
.
metrics
=
Object
.
keys
(
params
.
metricsSpec
||
{}).
reduce
((
acc
,
key
)
=>
{
this
.
metrics
=
Object
.
keys
(
params
.
metricsSpec
||
{}).
reduce
((
acc
,
key
)
=>
{
const
spec
=
params
.
metricsSpec
[
key
]
const
spec
=
params
.
metricsSpec
[
key
]
acc
[
key
]
=
new
spec
.
type
({
acc
[
key
]
=
new
spec
.
type
({
name
:
`
${
snakeCase
(
params
.
name
)}
_
${
s
nakeCase
(
key
)}
`
,
name
:
`
${
opSnakeCase
(
params
.
name
)}
_
${
opS
nakeCase
(
key
)}
`
,
help
:
spec
.
desc
,
help
:
spec
.
desc
,
labelNames
:
spec
.
labels
||
[],
labelNames
:
spec
.
labels
||
[],
})
})
...
@@ -198,7 +207,7 @@ export abstract class BaseServiceV2<
...
@@ -198,7 +207,7 @@ export abstract class BaseServiceV2<
// Gracefully handle stop signals.
// Gracefully handle stop signals.
const
stop
=
async
(
signal
:
string
)
=>
{
const
stop
=
async
(
signal
:
string
)
=>
{
this
.
logger
.
info
(
`stopping service`
,
{
signal
})
this
.
logger
.
info
(
`stopping service
with signal
`
,
{
signal
})
await
this
.
stop
()
await
this
.
stop
()
process
.
exit
(
0
)
process
.
exit
(
0
)
}
}
...
@@ -254,9 +263,11 @@ export abstract class BaseServiceV2<
...
@@ -254,9 +263,11 @@ export abstract class BaseServiceV2<
this
.
running
=
false
this
.
running
=
false
// Wait until the main loop has finished.
// Wait until the main loop has finished.
this
.
logger
.
info
(
'
stopping service, waiting for main loop to finish
'
)
while
(
!
this
.
done
)
{
while
(
!
this
.
done
)
{
await
sleep
(
1000
)
await
sleep
(
1000
)
}
}
this
.
logger
.
info
(
'
main loop finished, goodbye!
'
)
}
}
/**
/**
...
...
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