(
data: any,
retryAttempt: number
)
| 74 | } |
| 75 | |
| 76 | async function runTask( |
| 77 | data: any, |
| 78 | retryAttempt: number |
| 79 | ): Promise<any> { |
| 80 | let path: string | undefined |
| 81 | |
| 82 | if (cache === true) { |
| 83 | path = _getCachePath(fn_name, data) |
| 84 | if (_has(path)) { |
| 85 | try { |
| 86 | return _get(path) |
| 87 | } catch (error) { |
| 88 | if (!(error instanceof CacheMissException)) throw error |
| 89 | } |
| 90 | } |
| 91 | } else if (cache === 'REFRESH') { |
| 92 | path = _getCachePath(fn_name, data) |
| 93 | } |
| 94 | |
| 95 | let result: any |
| 96 | try { |
| 97 | result = await run({ data, metadata, taskId, parentTaskId, isAborted, pushData }) |
| 98 | if (result === undefined) { |
| 99 | result = null |
| 100 | } |
| 101 | |
| 102 | if (cache === true || cache === 'REFRESH') { |
| 103 | if (isDontCache(result)) { |
| 104 | _remove(path!) |
| 105 | } else { |
| 106 | writeJson(result, path!) |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | if (isDontCache(result)) { |
| 111 | if (!returnDontCacheAsIs) { |
| 112 | result = result.data |
| 113 | } |
| 114 | } |
| 115 | return result |
| 116 | } catch (error) { |
| 117 | if (error instanceof NotFoundException && !error.raisedOnce) { |
| 118 | if (error.raiseMaximum1Time) { |
| 119 | error.raisedOnce = true |
| 120 | } |
| 121 | throw error |
| 122 | } else if (mustRaiseExceptions && |
| 123 | isErrorsInstance(mustRaiseExceptions, error)[0]) { |
| 124 | if (createErrorLogs) { |
| 125 | saveErrorLogs(formatExc(error), data) |
| 126 | } |
| 127 | throw error |
| 128 | } |
| 129 | |
| 130 | if (maxRetry !== undefined && maxRetry !== null && maxRetry > retryAttempt) { |
| 131 | printExc(error) |
| 132 | if (retryWait) { |
| 133 | console.log(`Waiting for ${retryWait} seconds`) |
no test coverage detected