diff --git a/models/models.go b/models/models.go index 2d8bfcd..6387479 100644 --- a/models/models.go +++ b/models/models.go @@ -4,22 +4,21 @@ import ( "time" ) -// JobReq represents a job request. -type JobReq struct { - TaskName string `json:"task"` - JobID string `json:"job_id"` - Queue string `json:"queue"` - ETA string `json:"eta"` - Retries int `json:"retries"` - TTL int `json:"ttl"` - Args []string `json:"args"` - DB string `json:"db"` - - ttlDuration time.Duration -} - -// JobResp is the response sent to a job request. -type JobResp struct { +// JobRequest represents a job request with metadata and execution details. +type JobRequest struct { + TaskName string `json:"task"` + JobID string `json:"job_id"` + Queue string `json:"queue"` + ETA *time.Time `json:"eta"` + Retries int `json:"retries"` + TTL int `json:"ttl"` + Args []string `json:"args"` + DB string `json:"db"` + TTLDuration time.Duration `json:"-"` // Internal field, not serialized to JSON +} + +// JobResponse represents the response sent after processing a job. +type JobResponse struct { JobID string `json:"job_id"` TaskName string `json:"task"` Queue string `json:"queue"` @@ -27,37 +26,58 @@ type JobResp struct { Retries int `json:"retries"` } -// JobStatusResp represents the response of a single job. -type JobStatusResp struct { +// JobStatusResponse represents the status of a single job. +type JobStatusResponse struct { JobID string `json:"job_id"` State string `json:"state"` Count int `json:"count"` - Error string `json:"error"` + Error string `json:"error,omitempty"` } -// GroupReq represents a Jobrequest group. -type GroupReq struct { - GroupID string `json:"group_id"` - Jobs []JobReq `json:"jobs"` +// GroupRequest represents a group of job requests. +type GroupRequest struct { + GroupID string `json:"group_id"` + Jobs []JobRequest `json:"jobs"` } -// GroupResp is the response sent to a group job request. -type GroupResp struct { - GroupID string `json:"group_id"` - Jobs []JobResp `json:"jobs"` +// GroupResponse represents the response for a group job request. +type GroupResponse struct { + GroupID string `json:"group_id"` + Jobs []JobResponse `json:"jobs"` } -// GroupStatusResp represents the status of a group job. -type GroupStatusResp struct { - GroupID string `json:"group_id"` - State string `json:"state"` - Jobs []JobStatusResp `json:"jobs"` +// GroupStatusResponse represents the status of a group job. +type GroupStatusResponse struct { + GroupID string `json:"group_id"` + State string `json:"state"` + Jobs []JobStatusResponse `json:"jobs"` } -// HTTPResp represents a container for generic outgoing HTTP -// responses. -type HTTPResp struct { +// HTTPResponse represents a container for generic outgoing HTTP responses. +type HTTPResponse struct { Status string `json:"status"` Message string `json:"message,omitempty"` Data interface{} `json:"data"` } + +// NewJobRequest creates a new JobRequest with proper initialization. +func NewJobRequest(taskName, jobID, queue, db string, eta *time.Time, retries, ttl int, args []string) JobRequest { + return JobRequest{ + TaskName: taskName, + JobID: jobID, + Queue: queue, + ETA: eta, + Retries: retries, + TTL: ttl, + Args: args, + DB: db, + } +} + +// NewGroupRequest creates a new GroupRequest with proper initialization. +func NewGroupRequest(groupID string, jobs []JobRequest) GroupRequest { + return GroupRequest{ + GroupID: groupID, + Jobs: jobs, + } +}