Skip to content

Commit

Permalink
taskqueueworker: add support for mysql persistent
Browse files Browse the repository at this point in the history
  • Loading branch information
agungdwiprasetyo committed May 18, 2023
1 parent 7d5b660 commit 0904021
Show file tree
Hide file tree
Showing 10 changed files with 362 additions and 201 deletions.
15 changes: 15 additions & 0 deletions candihelper/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ const (
HeaderMIMEMultipartForm = "multipart/form-data"
// HeaderMIMEOctetStream const
HeaderMIMEOctetStream = "application/octet-stream"

// DateFormatMonday date format
DateFormatMonday = "Monday"
// DateFormatYYYYMM date format
DateFormatYYYYMM = "2006-01"
// DateFormatYYYYMMDD date format
DateFormatYYYYMMDD = "2006-01-02"
// DateFormatYYYYMMDDHHmmss date format
DateFormatYYYYMMDDHHmmss = "2006-01-02 15:04:05"
// DateFormatYYYYMMDDClean date format
DateFormatYYYYMMDDClean = "20060102"
// DateFormatHHmmss date format
DateFormatHHmm = "15:04"
// DateFormatDDMMYYYY date format
DateFormatDDMMYYYY = "02-01-2006"
)

var (
Expand Down
8 changes: 8 additions & 0 deletions candihelper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,3 +654,11 @@ func StringToByte(s string) (b []byte) {
bh.Len = sh.Len
return b
}

// ParseTimeToString helper, return empty string if zero time
func ParseTimeToString(date time.Time, format string) (res string) {
if !date.IsZero() {
res = date.Format(format)
}
return res
}
3 changes: 2 additions & 1 deletion cmd/candi/template_delivery_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,10 @@ func (h *TaskQueueHandler) handleTask{{upper (camel .ModuleName)}}(eventContext
// exec usecase
// h.uc.SomethingUsecase()
time.Sleep(1*time.Second) // just for example process
return &candishared.ErrorRetrier{
Delay: 2 * time.Second,
Delay: 1 * time.Second,
Message: "Error retry",
}
}
Expand Down
7 changes: 7 additions & 0 deletions codebase/app/task_queue_worker/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ func convertIncrementMap(mp map[string]int) map[string]interface{} {
}
return res
}

func normalizeCount(count int) int {
if count < 0 {
return 0
}
return count
}
13 changes: 7 additions & 6 deletions codebase/app/task_queue_worker/persistent_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,17 @@ func (f *Filter) ParseStartEndDate() (startDate, endDate time.Time) {

// CountTotalJob method
func (s *TaskSummary) CountTotalJob() int {
return s.Success + s.Queueing + s.Retrying + s.Failure + s.Stopped
return normalizeCount(s.Success) + normalizeCount(s.Queueing) + normalizeCount(s.Retrying) +
normalizeCount(s.Failure) + normalizeCount(s.Stopped)
}

// ToSummaryDetail method
func (s *TaskSummary) ToSummaryDetail() (detail SummaryDetail) {
detail.Failure = s.Failure
detail.Retrying = s.Retrying
detail.Success = s.Success
detail.Queueing = s.Queueing
detail.Stopped = s.Stopped
detail.Failure = normalizeCount(s.Failure)
detail.Retrying = normalizeCount(s.Retrying)
detail.Success = normalizeCount(s.Success)
detail.Queueing = normalizeCount(s.Queueing)
detail.Stopped = normalizeCount(s.Stopped)
return
}

Expand Down
Loading

0 comments on commit 0904021

Please sign in to comment.