asynq_service.go 1.3 KB
package domainService

import (
	"github.com/hibiken/asynq"
	"github.com/linmadan/egglib-go/utils/json"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)

func SendWorkshopWorkTimeStaticJob(productRecord *domain.ProductAttendanceRecord) error {
	return SendAsyncJob(domain.TaskKeyWorkshopWorkTimeRecordStatics(), productRecord)
}

func SendProductRecordStaticsJob(productRecord *domain.ProductRecord) error {
	task := asynq.NewTask(domain.TaskKeyPatternProductRecordStatics(), []byte(json.MarshalToString(productRecord)))

	client := asynq.NewClient(asynq.RedisClientOpt{Addr: constant.REDIS_ADDRESS})
	_, err := client.Enqueue(task)
	return err
}

func SendDeviceZkTecoReportJob(productRecord *domain.DeviceZkTeco) error {
	return SendAsyncJob(domain.TaskDeviceZkTecoReport(), productRecord)
}

func SendWorkshopDeviceData(productRecord *domain.DeviceCollection) error {
	return SendAsyncJob(domain.TaskDeviceCollection(), productRecord)
}

func SendAsyncJob(queueName string, job interface{}) error {
	task := asynq.NewTask(queueName, []byte(json.MarshalToString(job)))
	client := asynq.NewClient(asynq.RedisClientOpt{Addr: constant.REDIS_ADDRESS})
	_, err := client.Enqueue(task)
	return err
}