Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Nov 13, 2023
1 parent 984c63b commit d162d65
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 9 additions & 2 deletions routes/users/endpoints/create_data_task/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import (
"time"

"github.com/infinitybotlist/eureka/uapi/ratelimit"
"github.com/jackc/pgx/v5/pgtype"
"go.uber.org/zap"

docs "github.com/infinitybotlist/eureka/doclib"
"github.com/infinitybotlist/eureka/uapi"
)

const dataTaskExpiryTime = time.Hour * 1

func Docs() *docs.Doc {
return &docs.Doc{
Summary: "Create Data Task",
Expand Down Expand Up @@ -83,7 +86,7 @@ func Route(d uapi.RouteData, r *http.Request) uapi.HttpResponse {
err = state.Pool.QueryRow(d.Context, "INSERT INTO tasks (task_name, for_user, expiry, output) VALUES ($1, $2, $3, $4) RETURNING task_id",
taskName,
d.Auth.ID,
time.Hour*1,
dataTaskExpiryTime,
map[string]any{
"meta": map[string]any{
"request_ip": remoteIp[0],
Expand All @@ -103,6 +106,10 @@ func Route(d uapi.RouteData, r *http.Request) uapi.HttpResponse {
go assets.DataTask(taskId, d.Auth.ID, remoteIp[0], reqType == "true")

return uapi.HttpResponse{
Json: types.TaskCreateResponse{TaskID: taskId},
Json: types.TaskCreateResponse{
TaskID: taskId,
TaskName: taskName,
Expiry: pgtype.Interval{Microseconds: int64(dataTaskExpiryTime / time.Microsecond)},
},
}
}
8 changes: 6 additions & 2 deletions types/task.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package types

import "github.com/jackc/pgx/v5/pgtype"
import (
"github.com/jackc/pgx/v5/pgtype"
)

type TaskCreateResponse struct {
TaskID string `json:"task_id" description:"The ID of the newly created task"`
TaskID string `json:"task_id" description:"The ID of the newly created task"`
TaskName string `db:"task_name" json:"task_name" validate:"required" description:"The task name."`
Expiry pgtype.Interval `db:"expiry" json:"expiry" validate:"required" description:"The task expiry."`
}

// @ci table=tasks
Expand Down

0 comments on commit d162d65

Please sign in to comment.