tsk-7: Verify if scheduled message can be sent (#13)
Closes #7 Reviewed-on: #13 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/message/scheduling"
|
||||||
"git.kundeng.us/phoenix/textsender-models/tx0/token"
|
"git.kundeng.us/phoenix/textsender-models/tx0/token"
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/catapult/internal/app"
|
"git.kundeng.us/phoenix/catapult/internal/app"
|
||||||
@@ -53,6 +54,7 @@ func (s *Service) worker1() {
|
|||||||
return
|
return
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
// Do some work
|
// Do some work
|
||||||
|
now := time.Now()
|
||||||
log.Println("Worker 1: Processing...")
|
log.Println("Worker 1: Processing...")
|
||||||
if s.token == nil {
|
if s.token == nil {
|
||||||
catapultAuth := service.Auth{Application: s.App}
|
catapultAuth := service.Auth{Application: s.App}
|
||||||
@@ -70,6 +72,15 @@ func (s *Service) worker1() {
|
|||||||
} else {
|
} else {
|
||||||
if *exists {
|
if *exists {
|
||||||
fmt.Println("Id:", item.Id)
|
fmt.Println("Id:", item.Id)
|
||||||
|
fmt.Println("Created:", item.Created)
|
||||||
|
fmt.Println("Scheduled:", item.Scheduled)
|
||||||
|
fmt.Println("Status:", item.Status)
|
||||||
|
fmt.Println("User Id:", item.UserId)
|
||||||
|
if scheduledMessageValid(item, now) {
|
||||||
|
fmt.Println("Scheduled Message can be sent")
|
||||||
|
} else {
|
||||||
|
fmt.Println("Invalid scheduled message")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Empty queue")
|
fmt.Println("Empty queue")
|
||||||
}
|
}
|
||||||
@@ -119,3 +130,11 @@ func (s *Service) Stop() {
|
|||||||
s.wg.Wait()
|
s.wg.Wait()
|
||||||
log.Println("Service stopped gracefully")
|
log.Println("Service stopped gracefully")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func scheduledMessageValid(schMsg *scheduling.ScheduledMessage, now time.Time) bool {
|
||||||
|
if schMsg.Scheduled.Before(now) {
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user