我有一个长时间运行的导入脚本(~4分钟),它是由graphql突变启动的。登录到服务器后,我注意到在触发突变后恰好2分钟,它被重试,导致导入运行两次。
我猜这是由apollo-link中的某些功能引起的,但我已经看过那里的代码,但找不到一个选项来关闭它。
下面是我如何设置apollo的:
import ApolloClient from 'apollo-client'
import { ApolloLink } from 'apollo-link'
import { createHttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import config from 'src/config'
import { getItem } from 'src/utils/local-store'
const httpLink = createHttpLink({ uri: config.graphql })
const middlewareLink = new ApolloLink((operation, forward) => {
const token = getItem(config.jwtKey)
if (token) {
operation.setContext({
headers: {
Authorization: `Bearer ${token}`
}
})
}
return forward(operation)
})
const client = new ApolloClient({
link: middlewareLink.concat(httpLink),
cache: new InMemoryCache().restore(window.__APOLLO_STATE__ || {})
})
export default client变异本身并没有什么奇特之处:
export class ReleaseImport extends PureComponent {
// ...
handleSaveRelease = async () => {
const { save, artistId } = this.props
const { id, releaseGroupId } = this.state
await save({ variables: { release: { id, releaseGroupId }, artistId } })
}
// ...
}
const saveArtistRelease = gql`
mutation ImportSaveArtistRelease($release: ImportReleaseInput!, $artistId: Int!) {
importSaveArtistRelease(release: $release, artistId: $artistId) {
id
}
}
`
export default compose(
graphql(saveArtistRelease, {
name: 'save'
})
)(ReleaseImport)我只是想关闭这个重试功能。谢谢。
发布于 2018-02-12 21:48:17
我找错人了。
结果是节点的默认超时时间是2分钟,如果超时到了2分钟,它将重试请求。
在我的例子中,使用Koa,修复方法很简单:
// make timeout value 5 minutes
app.use(async (ctx, next) => {
ctx.req.setTimeout(5 * 60 * 1000)
await next()
})https://stackoverflow.com/questions/48661753
复制相似问题