Skip to content
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

Add default logger + log boolean to CN asyncretry wrapper + renaming [Content Node] #3113

Merged
merged 4 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions creator-node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class TrackTranscodeHandoffManager {
return resp
}
},
asyncFnLabel: 'polling transcode',
logLabel: 'polling transcode',
options: {
retries: POLLING_TRANSCODE_AND_SEGMENTS_RETRIES,
minTimeout: POLLING_TRANSCODE_AND_SEGMENTS_MIN_TIMEOUT,
Expand Down Expand Up @@ -373,7 +373,7 @@ class TrackTranscodeHandoffManager {
timeout: SEND_TRANSCODE_AND_SEGMENT_REQUEST_TIMEOUT_MS
})
},
asyncFnLabel: 'transcode and segment'
logLabel: 'transcode and segment'
})

return resp.data.data.uuid
Expand Down Expand Up @@ -431,7 +431,7 @@ class TrackTranscodeHandoffManager {
timeout: FETCH_PROCESSING_STATUS_TIMEOUT_MS
})
},
asyncFnLabel: 'fetch track content processing status'
logLabel: 'fetch track content processing status'
})

return body.data
Expand Down Expand Up @@ -467,7 +467,7 @@ class TrackTranscodeHandoffManager {
timeout: FETCH_STREAM_TIMEOUT_MS
})
},
asyncFnLabel: 'fetch segment'
logLabel: 'fetch segment'
})
}

Expand Down Expand Up @@ -501,7 +501,7 @@ class TrackTranscodeHandoffManager {
timeout: FETCH_STREAM_TIMEOUT_MS
})
},
asyncFnLabel: 'fetch transcode'
logLabel: 'fetch transcode'
})
}

Expand Down Expand Up @@ -535,7 +535,7 @@ class TrackTranscodeHandoffManager {
timeout: FETCH_STREAM_TIMEOUT_MS
})
},
asyncFnLabel: 'fetch m3u8'
logLabel: 'fetch m3u8'
})
}

Expand All @@ -560,7 +560,7 @@ class TrackTranscodeHandoffManager {
* @param {Object} param
* @param {Object} param.logger
* @param {func} param.asyncFn the fn to asynchronously retry
* @param {string} param.asyncFnLabel the task label used to print on retry. used for debugging purposes
* @param {string} param.logLabel the task label used to print on retry. used for debugging purposes
* @param {Object} param.options optional options. defaults to the params listed below if not explicitly passed in
* @param {number} [param.options.factor=2] the exponential factor
* @param {number} [param.options.retries=5] the max number of retries. defaulted to 5
Expand All @@ -572,7 +572,7 @@ class TrackTranscodeHandoffManager {
static asyncRetryNotOn404({
logger,
asyncFn: inputAsyncFn,
asyncFnLabel,
logLabel,
options = {}
}) {
const asyncFn = async (bail) => {
Expand All @@ -593,7 +593,7 @@ class TrackTranscodeHandoffManager {
return resp
}

return Utils.asyncRetry({ logger, asyncFn, asyncFnLabel, options })
return Utils.asyncRetry({ logger, asyncFn, logLabel, options })
}
}

Expand Down
2 changes: 1 addition & 1 deletion creator-node/src/snapbackSM/peerSetManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class PeerSetManager {
try {
// Request all users that have this node as a replica (either primary or secondary)
const resp = await Utils.asyncRetry({
asyncFnLabel: 'fetch all users with this node in replica',
logLabel: 'fetch all users with this node in replica',
asyncFn: async () => {
return axios({
method: 'get',
Expand Down
2 changes: 1 addition & 1 deletion creator-node/src/snapbackSM/snapbackSM.js
Original file line number Diff line number Diff line change
Expand Up @@ -1909,7 +1909,7 @@ class SnapbackSM {
try {
// Request all users that have this node as a replica (either primary or secondary)
const resp = await Utils.asyncRetry({
asyncFnLabel: 'fetch all users with this node in replica',
logLabel: 'fetch all users with this node in replica',
asyncFn: async () => {
return axios({
method: 'get',
Expand Down
20 changes: 15 additions & 5 deletions creator-node/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const stream = require('stream')
const retry = require('async-retry')
const { promisify } = require('util')
const pipeline = promisify(stream.pipeline)
const { logger: genericLogger } = require('./logging.js')

const models = require('./models')
const redis = require('./redis')
Expand Down Expand Up @@ -350,26 +351,35 @@ function currentNodeShouldHandleTranscode({
*
* options described here https://github.com/tim-kos/node-retry#retrytimeoutsoptions
* @param {Object} param
* @param {Object} param.logger
* @param {func} param.asyncFn the fn to asynchronously retry
* @param {string} param.asyncFnLabel the task label used to print on retry. used for debugging purposes
* @param {Object} param.options optional options. defaults to the params listed below if not explicitly passed in
* @param {number} [param.options.factor=2] the exponential factor
* @param {number} [param.options.retries=5] the max number of retries. defaulted to 5
* @param {number} [param.options.minTimeout=1000] minimum number of ms to wait after first retry. defaulted to 1000ms
* @param {number} [param.options.maxTimeout=5000] maximum number of ms between two retries. defaulted to 5000ms
* @param {func} [param.options.onRetry] fn that gets called per retry
* @param {Object} param.logger
* @param {Boolean} param.log enables/disables logging
* @param {string?} param.logLabel
* @returns the fn response if success, or throws an error
*/
function asyncRetry({ logger, asyncFn, asyncFnLabel, options = {} }) {
function asyncRetry({
asyncFn,
options = {},
logger = genericLogger,
log = true,
logLabel = null
}) {
options = {
retries: 5,
factor: 2,
minTimeout: 1000,
maxTimeout: 5000,
onRetry: (err, i) => {
if (err) {
logger.warn(`${asyncFnLabel} ${i} retry error: `, err)
if (err && log) {
const logPrefix =
(logLabel ? `[${logLabel}] ` : '') + `[asyncRetry] [attempt #${i}]`
logger.warn(`${logPrefix}: `, err)
}
},
...options
Expand Down