-
Notifications
You must be signed in to change notification settings - Fork 735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: allow configuring crawler statistics #2213
Conversation
/** | ||
* Manually reset KV store entry for the statistics, ignoring the {@apilink StatisticsOptions.enablePersistence} flag | ||
*/ | ||
async resetStoreForce() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need a separate method for this? i'd probably prefer force
parameter here
/** | ||
* Same as {@apilink Statistics.persistState}, but ignores the {@apilink StatisticsOptions.enablePersistence} flag | ||
*/ | ||
async persistStateForce() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just Banan's comments
Co-authored-by: Martin Adámek <banan23@gmail.com>
@@ -159,17 +159,15 @@ export class Statistics { | |||
this._teardown(); | |||
} | |||
|
|||
async resetStore() { | |||
if (!this.enablePersistence) { | |||
async resetStore(opts?: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please create a new interface for this
async persistState() { | ||
// this might be called before startCapturing was called without using await, should not crash | ||
if (!this.enablePersistence || !this.keyValueStore) { | ||
async persistState(opts?: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, you can use the same interface (try to find some generic name that would fit both methods)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, added. I'm not really sure though whether it would be better to add the interface locally to each file or create a shared one
if (!this.enablePersistence) { | ||
async resetStore(opts?: { | ||
/** | ||
* If true, manually reset KV store entry for the statistics, ignoring the {@apilink StatisticsOptions.enablePersistence} flag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure about the word "manually" here. If you call this method, its always manual usage, regardless of the options.
@@ -309,17 +307,15 @@ export class SessionPool extends EventEmitter { | |||
return this._createSession(); | |||
} | |||
|
|||
async resetStore() { | |||
if (!this.enablePersistence) { | |||
async resetStore(opts?: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
@@ -339,17 +335,15 @@ export class SessionPool extends EventEmitter { | |||
* Persists the current state of the `SessionPool` into the default {@apilink KeyValueStore}. | |||
* The state is persisted automatically in regular intervals. | |||
*/ | |||
async persistState(): Promise<void> { | |||
if (!this.enablePersistence) { | |||
async persistState(opts?: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here
Co-authored-by: Martin Adámek <banan23@gmail.com>
Co-authored-by: Martin Adámek <banan23@gmail.com>
Co-authored-by: Martin Adámek <banan23@gmail.com>
Co-authored-by: Martin Adámek <banan23@gmail.com>
}) { | ||
if (!this.enablePersistence && !opts?.force) { | ||
async resetStore(opts?: PersistenceOptionsOverrides) { | ||
if (!(this.enablePersistence || opts?.enablePersistence)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please apply this change to all the occurrences
if (!(this.enablePersistence || opts?.enablePersistence)) { | |
if (!this.enablePersistence && !opts?.enablePersistence) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just few comments for now
force?: boolean; | ||
}) { | ||
if (!this.enablePersistence && !opts?.force) { | ||
async resetStore(opts?: PersistenceOptionsOverrides) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets not use abbreviations unless needed (e.g. when there is a collision)
async resetStore(opts?: PersistenceOptionsOverrides) { | |
async resetStore(options?: PersistenceOptionsOverrides) { |
async resetStore(opts?: PersistenceOptionsOverrides) { | ||
if (!this.enablePersistence && !opts?.enablePersistence) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i like to keep one blank line after control statements like if/for/while/etc
, this applies to other places in the PR too (e.g. the persistState
method), take it as a rule of thumb
} | |
} | |
/** | ||
* Override persistence-related options provided in {@apilink SessionPoolOptions} for a single method call | ||
*/ | ||
interface PersistenceOptionsOverrides { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to have a single interface for both since it's exactly the same. Let's export it and reuse it instead of creating two local implementations.
I also don't like the name very much, will try to come up with something else, I don't have any ideas right now :]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've restructured it a bit, so that the same interface is used in the constructor and options
parameter. Does that look okay?
I'm also not sure where to actually put this interface in the project hierarchy. I don't see a matching module for utilities/types shared by both statistics and session pool
FYI the tests are failing, so if you are waiting for my review - its actually me who is waiting for you to fix them first :] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
Allow disabling automatic persistence in Statistics and SessionPool.
Add additional methods for manual disabling in case it's needed, but just not the automatic one
Closes #1789