-
Notifications
You must be signed in to change notification settings - Fork 1
# 283 SlackのDM送信を5分ごとに実行する処理の追加 #322
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
Open
taminororo
wants to merge
10
commits into
develop
Choose a base branch
from
feat/kanba/286-regular-execution-of-notif
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7cc59c8
feat: デモコードでStart()関数の実装を理解
taminororo 191b35b
feat: di.goに5分ごとに未送信の通知をpushするgoroutine発火のコードを書く
taminororo de5b954
feat: デモコードを追加して理解を深める
taminororo 18ca2a1
feat: 通知の未送信ログを5分間隔で自動送信するschedulerを追加(デモの削除)
taminororo b2dc296
fix: コメントの削除
taminororo c680c76
fix: 不要なNew関数のコメント削除
taminororo 2261d12
https://go.dev/blog/context
taminororo 4f63f5b
feat: スケジューラ起動直後に job を即時実行
taminororo 3c233e3
fix: RunServer/InitializeServer を error 返却にし後始末のスキップを防止
taminororo 096332e
Merge remote-tracking branch 'origin/develop' into feat/kanba/286-reg…
taminororo 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 hidden or 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 hidden or 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 hidden or 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 @@ | ||
| package scheduler | ||
|
|
||
| import ( | ||
| "context" | ||
| "log" | ||
| "time" | ||
| ) | ||
|
|
||
| // Job は scheduler が定期実行する処理。usecase を import せず関数型で受け取り、 | ||
| // scheduler と業務ロジックを疎結合に保つ。 | ||
| type Job func(ctx context.Context) error | ||
|
|
||
| // Scheduler は「名前・間隔・実行する処理」を保持する。 | ||
| type Scheduler struct { | ||
| name string | ||
| interval time.Duration | ||
| job Job | ||
| } | ||
|
|
||
| // New はコンストラクタでSchedulerを生成する。 | ||
| func New(name string, interval time.Duration, job Job) *Scheduler { | ||
| return &Scheduler{name: name, interval: interval, job: job} | ||
| } | ||
|
|
||
| // Start は ticker ループを goroutine で起動し、即座に return する。 | ||
| // interval ごとに job を実行し、job が返したエラーはログ出力のみ(ループは止めない)。 | ||
| func (s *Scheduler) Start(ctx context.Context) { | ||
| go func() { | ||
| if err := s.job(ctx); err != nil { | ||
| log.Printf("[scheduler:%s] job error (initial): %v", s.name, err) | ||
| } | ||
|
|
||
| ticker := time.NewTicker(s.interval) | ||
| defer ticker.Stop() | ||
| for { | ||
| select { | ||
| case <-ticker.C: | ||
| if err := s.job(ctx); err != nil { | ||
| log.Printf("[scheduler:%s] job error: %v", s.name, err) | ||
| } | ||
| case <-ctx.Done(): | ||
| log.Printf("[scheduler:%s] stopped: %v", s.name, ctx.Err()) | ||
| return | ||
| } | ||
|
|
||
| } | ||
| }() | ||
| } | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.