Skip to content
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

Update models.go #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 55 additions & 35 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,80 @@ 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"`
ETA *time.Time `json:"eta"`
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,
}
}