-
Notifications
You must be signed in to change notification settings - Fork 219
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: 110268 111686 get questionnaire order periodically #7153
Merged
hakumizuki
merged 10 commits into
weseek:feat/questionnaire
from
arafubeatbox:feat/110268-111686-get-questionnaire-order-periodically
Jan 6, 2023
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ea5c026
refs 111686: questionnaire cronjob
arafubeatbox 8fd914b
refs 111686: refactor
arafubeatbox 0646bf1
111686: add node-cron
arafubeatbox cf1b63e
Merge branch 'master' into feat/110268-111686-get-questionnaire-order…
arafubeatbox d7ddea5
refs 111686: debug
arafubeatbox 0bb44ac
refs 111686: apply feedback
arafubeatbox 8ad1092
Merge branch 'master' into feat/110268-111686-get-questionnaire-order…
arafubeatbox d5795c1
refs 111686: apply feedback
arafubeatbox 97e235a
refs 111686: use axios-retry
arafubeatbox 57e4325
rm await
hakumizuki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import axiosRetry from 'axios-retry'; | ||
|
||
import { getRandomIntInRange } from '~/utils/rand'; | ||
import { sleep } from '~/utils/sleep'; | ||
|
||
const axios = require('axios').default; | ||
const nodeCron = require('node-cron'); | ||
|
||
axiosRetry(axios, { retries: 3 }); | ||
|
||
class QuestionnaireCronService { | ||
|
||
crowi: any; | ||
|
||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
constructor(crowi) { | ||
this.crowi = crowi; | ||
} | ||
|
||
setUpCron(): void { | ||
const cronSchedule = this.crowi.configManager?.getConfig('crowi', 'app:questionnaireCronSchedule'); | ||
const maxHoursUntilRequest = this.crowi.configManager?.getConfig('crowi', 'app:questionnaireCronMaxHoursUntilRequest'); | ||
|
||
const maxSecondsUntilRequest = maxHoursUntilRequest * 60 * 60; | ||
this.questionnaireOrderGetCron(cronSchedule, maxSecondsUntilRequest); | ||
} | ||
|
||
questionnaireOrderGetCron(cronSchedule: string, maxSecondsUntilRequest: number): void { | ||
const growiQuestionnaireServerOrigin = this.crowi.configManager?.getConfig('crowi', 'app:growiQuestionnaireServerOrigin'); | ||
nodeCron.schedule(cronSchedule, async() => { | ||
const secToSleep = getRandomIntInRange(0, maxSecondsUntilRequest); | ||
|
||
await sleep(secToSleep * 1000); | ||
|
||
try { | ||
const response = await axios.get(`${growiQuestionnaireServerOrigin}/questionnaire-order/index`); | ||
console.log(response.data); | ||
} | ||
catch (e) { | ||
console.log(e); | ||
} | ||
|
||
}).start(); | ||
} | ||
|
||
} | ||
|
||
export default QuestionnaireCronService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const getRandomIntInRange = (min: number, max: number): number => { | ||
const minInt = Math.ceil(min); | ||
const maxInt = Math.floor(max); | ||
return Math.floor(Math.random() * (maxInt - minInt) + minInt); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const sleep = (msec: number): Promise<void> => new Promise(resolve => setTimeout(resolve, msec)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
node 内の cron job 実行のために追加しました。
LICENSE 的に使って大丈夫だと思っています。
THIRD-PARTY-NOTICES はほぼ武井さんしかいじっていなかったので一旦いじりませんでした。