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

[FEAT][API] Create signal metrics job #76

Open
youen opened this issue Mar 31, 2024 · 0 comments
Open

[FEAT][API] Create signal metrics job #76

youen opened this issue Mar 31, 2024 · 0 comments

Comments

@youen
Copy link
Collaborator

youen commented Mar 31, 2024

Description

Create a signal metrics job.

Request

Method

POST

URL

/jobs/metrics/signal

Request Parameters

Parameter Description Required example
kind JobKind.signal_metrics

Request Body

{
  "parameters": {
    "data_source": "my_data_source",
    "signal": "my_signal"
  }
}

Result

Result parameters

Parameter Description Required example
id Id 123e4567-e89b-12d3-a456-426655440000
kind JobKind.signal_metrics
created_at Created At 2023-05-18T10:10:10.000Z
status Status JobStatus.pending
error_message Error Message null
traceback Traceback null
result Result null
parameters Parameters { "data_source": "my_data_source", "signal": "my_signal" }
current_progress Current Progress null

Result Body

{
  "id": "123e4567-e89b-12d3-a456-426655440000",
  "kind": "signal_metrics",
  "created_at": "2023-05-18T10:10:10.000Z",
  "status": "pending",
  "error_message": null,
  "traceback": null,
  "result": null,
  "parameters": {
    "data_source": "my_data_source",
    "signal": "my_signal"
  },
  "current_progress": null
}

Example Curl Request

Request

curl -X POST \
  http://localhost:8080/jobs/metrics/signal \
  -H 'Content-Type: application/json' \
  -d '{
  "parameters": {
    "data_source": "my_data_source",
    "signal": "my_signal"
  }
}'

Curl Response

{
  "id": "123e4567-e89b-12d3-a456-426655440000",
  "kind": "signal_metrics",
  "created_at": "2023-05-18T10:10:10.000Z",
  "status": "pending",
  "error_message": null,
  "traceback": null,
  "result": null,
  "parameters": {
    "data_source": "my_data_source",
    "signal": "my_signal"
  },
  "current_progress": null
}

Go server

Struct

type CreateSignalMetricsJobRequest struct {
	Kind       JobKind                       `json:"kind"`
	Parameters SignalMetricsParametersRequest `json:"parameters"`
}

Handler

func (h *jobHandler) CreateSignalMetricsJob(w http.ResponseWriter, r *http.Request) {
	var req CreateSignalMetricsJobRequest
	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		h.l.Println(err)
		w.WriteHeader(http.StatusInternalServerError)
		fmt.Fprintln(w, err)
		return
	}
	r.Body = ioutil.NopCloser(bytes.NewBuffer(body))
	err = json.Unmarshal(body, &req)
	if err != nil {
		h.l.Printf("Failed to unmarshal request: %s", err)
		w.WriteHeader(http.StatusBadRequest)
		fmt.Fprintln(w, "Failed to unmarshal request")
		return
	}

	job, err := h.jobService.CreateSignalMetricsJob(req)
	if err != nil {
		h.l.Printf("Failed to create job: %s", err)
		w.WriteHeader(http.StatusInternalServerError)
		fmt.Fprintln(w, "Failed to create job")
		return
	}

	w.WriteHeader(http.StatusCreated)
	w.Header().Set("Content-Type", "application/json")
	enc := json.NewEncoder(w)
	err = enc.Encode(job)
	if err != nil {
		h.l.Printf("Failed to encode response: %s", err)
		w.WriteHeader(http.StatusInternalServerError)
		fmt.Fprintln(w, "Failed to encode response")
		return
	}
}

Links

Automated Issue Details

Dear visitor,

This issue has been automatically generated from the Octopize project avatar-python to make SIGO compatible. Please vote with a thumbs up or thumbs down to assess the quality of the automatic generation.

Best regards,
The SIGO Team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant