Просмотр исходного кода

set timeout between proxy and GROWI

Yuki Takei 4 лет назад
Родитель
Сommit
0ca40ce576

+ 14 - 6
packages/app/src/server/routes/apiv3/slack-integration-settings.js

@@ -7,7 +7,10 @@ const axios = require('axios');
 const urljoin = require('url-join');
 const urljoin = require('url-join');
 
 
 const {
 const {
-  getConnectionStatus, getConnectionStatuses, sendSuccessMessage, defaultSupportedCommandsNameForBroadcastUse, defaultSupportedCommandsNameForSingleUse,
+  getConnectionStatus, getConnectionStatuses,
+  sendSuccessMessage,
+  defaultSupportedCommandsNameForBroadcastUse, defaultSupportedCommandsNameForSingleUse,
+  REQUEST_TIMEOUT_FOR_GTOP,
 } = require('@growi/slack');
 } = require('@growi/slack');
 
 
 const ErrorV3 = require('../../models/vo/error-apiv3');
 const ErrorV3 = require('../../models/vo/error-apiv3');
@@ -113,6 +116,7 @@ module.exports = (crowi) => {
     const result = await axios.get(urljoin(proxyUri, '/g2s/connection-status'), {
     const result = await axios.get(urljoin(proxyUri, '/g2s/connection-status'), {
       headers: {
       headers: {
         'x-growi-gtop-tokens': csv,
         'x-growi-gtop-tokens': csv,
+        timeout: REQUEST_TIMEOUT_FOR_GTOP,
       },
       },
     });
     });
 
 
@@ -125,11 +129,15 @@ module.exports = (crowi) => {
       throw new Error('Proxy URL is not registered');
       throw new Error('Proxy URL is not registered');
     }
     }
 
 
-    const headers = {
+    const result = await axios[method](
+      urljoin(proxyUri, endpoint),
+      body, {
+        headers: {
       'x-growi-gtop-tokens': token,
       'x-growi-gtop-tokens': token,
-    };
-
-    const result = await axios[method](urljoin(proxyUri, endpoint), body, { headers });
+        },
+        timeout: REQUEST_TIMEOUT_FOR_GTOP,
+      },
+    );
 
 
     return result.data;
     return result.data;
   }
   }
@@ -212,7 +220,7 @@ module.exports = (crowi) => {
           });
           });
         }
         }
         catch (e) {
         catch (e) {
-          errorMsg = 'Incorrect Proxy URL';
+          errorMsg = 'Something went wrong when retrieving information from Proxy Server.';
           errorCode = 'test-connection-failed';
           errorCode = 'test-connection-failed';
           logger.error(errorMsg, e);
           logger.error(errorMsg, e);
         }
         }

+ 4 - 0
packages/slack/src/index.ts

@@ -1,3 +1,7 @@
+export const REQUEST_TIMEOUT_FOR_GTOP = 10000;
+
+export const REQUEST_TIMEOUT_FOR_PTOG = 10000;
+
 export const supportedSlackCommands: string[] = [
 export const supportedSlackCommands: string[] = [
   '/growi',
   '/growi',
 ];
 ];

+ 2 - 1
packages/slackbot-proxy/src/controllers/growi-to-slack.ts

@@ -8,7 +8,7 @@ import { addHours } from 'date-fns';
 import { WebAPICallResult } from '@slack/web-api';
 import { WebAPICallResult } from '@slack/web-api';
 
 
 import {
 import {
-  verifyGrowiToSlackRequest, getConnectionStatuses, getConnectionStatus, generateWebClient,
+  verifyGrowiToSlackRequest, getConnectionStatuses, getConnectionStatus, generateWebClient, REQUEST_TIMEOUT_FOR_PTOG,
 } from '@growi/slack';
 } from '@growi/slack';
 
 
 import { WebclientRes, AddWebclientResponseToRes } from '~/middlewares/slack-to-growi/add-webclient-response-to-res';
 import { WebclientRes, AddWebclientResponseToRes } from '~/middlewares/slack-to-growi/add-webclient-response-to-res';
@@ -61,6 +61,7 @@ export class GrowiToSlackCtrl {
       headers: {
       headers: {
         'x-growi-ptog-tokens': tokenPtoG,
         'x-growi-ptog-tokens': tokenPtoG,
       },
       },
+      timeout: REQUEST_TIMEOUT_FOR_PTOG,
     });
     });
   }
   }
 
 

+ 3 - 1
packages/slackbot-proxy/src/controllers/slack.ts

@@ -10,7 +10,7 @@ import { Installation } from '@slack/oauth';
 
 
 import {
 import {
   markdownSectionBlock, GrowiCommand, parseSlashCommand, postEphemeralErrors, verifySlackRequest, generateWebClient,
   markdownSectionBlock, GrowiCommand, parseSlashCommand, postEphemeralErrors, verifySlackRequest, generateWebClient,
-  InvalidGrowiCommandError, requiredScopes, postWelcomeMessage, publishInitialHomeView,
+  InvalidGrowiCommandError, requiredScopes, postWelcomeMessage, publishInitialHomeView, REQUEST_TIMEOUT_FOR_PTOG,
 } from '@growi/slack';
 } from '@growi/slack';
 
 
 import { Relation } from '~/entities/relation';
 import { Relation } from '~/entities/relation';
@@ -84,6 +84,7 @@ export class SlackCtrl {
         headers: {
         headers: {
           'x-growi-ptog-tokens': relation.tokenPtoG,
           'x-growi-ptog-tokens': relation.tokenPtoG,
         },
         },
+        timeout: REQUEST_TIMEOUT_FOR_PTOG,
       });
       });
     });
     });
 
 
@@ -315,6 +316,7 @@ export class SlackCtrl {
         headers: {
         headers: {
           'x-growi-ptog-tokens': relation.tokenPtoG,
           'x-growi-ptog-tokens': relation.tokenPtoG,
         },
         },
+        timeout: REQUEST_TIMEOUT_FOR_PTOG,
       });
       });
     }
     }
     catch (err) {
     catch (err) {

+ 4 - 0
packages/slackbot-proxy/src/services/RelationsService.ts

@@ -1,7 +1,10 @@
 import { Inject, Service } from '@tsed/di';
 import { Inject, Service } from '@tsed/di';
+
 import axios from 'axios';
 import axios from 'axios';
 import { addHours } from 'date-fns';
 import { addHours } from 'date-fns';
 
 
+import { REQUEST_TIMEOUT_FOR_PTOG } from '@growi/slack';
+
 import { Relation } from '~/entities/relation';
 import { Relation } from '~/entities/relation';
 import { RelationRepository } from '~/repositories/relation';
 import { RelationRepository } from '~/repositories/relation';
 
 
@@ -22,6 +25,7 @@ export class RelationsService {
       headers: {
       headers: {
         'x-growi-ptog-tokens': relation.tokenPtoG,
         'x-growi-ptog-tokens': relation.tokenPtoG,
       },
       },
+      timeout: REQUEST_TIMEOUT_FOR_PTOG,
     });
     });
   }
   }