-
Notifications
You must be signed in to change notification settings - Fork 736
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
Changes from 1 commit
6b9cd5a
99c1880
9f4e015
0adb7d6
54a752f
1ca2536
8f3a10e
8da3b0c
5f8c3b6
a4eca60
a611e07
161c185
fc0b44d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -159,17 +159,15 @@ export class Statistics { | |||||||
this._teardown(); | ||||||||
} | ||||||||
|
||||||||
async resetStore() { | ||||||||
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 commentThe 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. |
||||||||
*/ | ||||||||
force?: boolean; | ||||||||
}) { | ||||||||
if (!this.enablePersistence && opts?.force !== true) { | ||||||||
foxt451 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
return; | ||||||||
} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i like to keep one blank line after control statements like
Suggested change
|
||||||||
return this.resetStoreForce(); | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
* Manually reset KV store entry for the statistics, ignoring the {@apilink StatisticsOptions.enablePersistence} flag | ||||||||
*/ | ||||||||
async resetStoreForce() { | ||||||||
if (!this.keyValueStore) { | ||||||||
return; | ||||||||
} | ||||||||
|
@@ -300,18 +298,15 @@ export class Statistics { | |||||||
/** | ||||||||
* Persist internal state to the key value store | ||||||||
*/ | ||||||||
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 commentThe 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 commentThe 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 true, ignore the {@apilink StatisticsOptions.enablePersistence} flag | ||||||||
*/ | ||||||||
force?: boolean; | ||||||||
}) { | ||||||||
if (!this.enablePersistence && opts?.force !== true) { | ||||||||
foxt451 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
return; | ||||||||
} | ||||||||
return this.persistStateForce(); | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
* Same as {@apilink Statistics.persistState}, but ignores the {@apilink StatisticsOptions.enablePersistence} flag | ||||||||
*/ | ||||||||
async persistStateForce() { | ||||||||
// this might be called before startCapturing was called without using await, should not crash | ||||||||
if (!this.keyValueStore) { | ||||||||
return; | ||||||||
|
@@ -438,7 +433,6 @@ export interface StatisticsOptions { | |||||||
|
||||||||
/** | ||||||||
* Use this flag to disable or enable periodic statistics persistence to key value store. | ||||||||
* You can persist to KV store or reset the record there manually by calling {@apilink Statistics.persistStateForce} or {@apilink Statistics.resetStoreForce} | ||||||||
* @default true | ||||||||
*/ | ||||||||
enablePersistence?: boolean; | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,8 +61,6 @@ export interface SessionPoolOptions { | |
|
||
/** | ||
* If set to true, `SessionPool` will periodically persist its state to the key-value store. | ||
* Othewise, {@apilink SessionPool.persistState} and {@apilink SessionPool.resetStore} will have no effect, | ||
* but you will still be able to call their "*Force" counterparts for manual resetting and persisting. | ||
* @default true | ||
*/ | ||
enablePersistence?: boolean; | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
/** | ||
* If true, manually reset KV store entry, ignoring the {@apilink SessionPoolOptions.enablePersistence} flag | ||
*/ | ||
force?: boolean; | ||
}) { | ||
if (!this.enablePersistence && opts?.force !== true) { | ||
foxt451 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return; | ||
} | ||
return this.resetStoreForce(); | ||
} | ||
|
||
/** | ||
* Manually reset KV store entry for the the session pool state, ignoring the {@apilink SessionPoolOptions.enablePersistence} option. | ||
*/ | ||
async resetStoreForce() { | ||
await this.keyValueStore?.setValue(this.persistStateKey, null); | ||
} | ||
|
||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. and here |
||
/** | ||
* If true, ignore the {@apilink SessionPoolOptions.enablePersistence} flag | ||
*/ | ||
force?: boolean; | ||
}): Promise<void> { | ||
if (!this.enablePersistence && opts?.force !== true) { | ||
foxt451 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return; | ||
} | ||
return this.persistStateForce(); | ||
} | ||
|
||
/** | ||
* Like {@apilink SessionPool.persistState}, but ignores the {@apilink SessionPoolOptions.enablePersistence} option. | ||
*/ | ||
async persistStateForce() { | ||
this.log.debug('Persisting state', { | ||
persistStateKeyValueStoreId: this.persistStateKeyValueStoreId, | ||
persistStateKey: this.persistStateKey, | ||
|
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