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] add Signal Metrics Batch Job #75

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

[FEAT][API] add Signal Metrics Batch Job #75

youen opened this issue Mar 31, 2024 · 0 comments

Comments

@youen
Copy link
Collaborator

youen commented Mar 31, 2024

Description

This feature adds an API to create a Signal Metrics Batch Job.

Request

Method

POST

URL

/jobs/metrics/signal_batch

Request Parameters

None

Request Body

{
  "kind": "signal_metrics_batch",
  "parameters": {
    "signals": [
      "signal_name_1",
      "signal_name_2"
    ],
    "start_date": "2023-01-01",
    "end_date": "2023-01-31"
  }
}

Result

Result parameters

Parameter Description Required example
id The ID of the job. yes 12345678-1234-1234-1234-123456789012
kind The kind of the job. yes signal_metrics_batch
created_at The time when the job was created. yes 2023-01-01T00:00:00Z
status The status of the job. yes pending
error_message The error message if the job failed. no null
traceback The traceback if the job failed. no null
result The result of the job if it succeeded. no null
parameters The parameters of the job. yes {"signals": ["signal_name_1", "signal_name_2"], "start_date": "2023-01-01", "end_date": "2023-01-31"}
current_progress The current progress of the job. no null

Result Body

{
  "id": "12345678-1234-1234-1234-123456789012",
  "kind": "signal_metrics_batch",
  "created_at": "2023-01-01T00:00:00Z",
  "status": "pending",
  "error_message": null,
  "traceback": null,
  "result": null,
  "parameters": {
    "signals": ["signal_name_1", "signal_name_2"],
    "start_date": "2023-01-01",
    "end_date": "2023-01-31"
  },
  "current_progress": null
}

Example Curl Request

Request

curl -X POST -H "Content-Type: application/json" -d '{"kind": "signal_metrics_batch", "parameters": {"signals": ["signal_name_1", "signal_name_2"], "start_date": "2023-01-01", "end_date": "2023-01-31"}}' http://localhost:8080/jobs/metrics/signal_batch

Curl Response

HTTP/1.1 200 OK
Content-Type: application/json

{
  "id": "12345678-1234-1234-1234-123456789012",
  "kind": "signal_metrics_batch",
  "created_at": "2023-01-01T00:00:00Z",
  "status": "pending",
  "error_message": null,
  "traceback": null,
  "result": null,
  "parameters": {
    "signals": ["signal_name_1", "signal_name_2"],
    "start_date": "2023-01-01",
    "end_date": "2023-01-31"
  },
  "current_progress": null
}

Go server

Struct

type SignalMetricsBatchJobCreateRequest struct {
  Kind string `json:"kind"`
  Parameters SignalMetricsBatchParameters `json:"parameters"`
}

Handler

func createSignalMetricsBatchJob(w http.ResponseWriter, r *http.Request) {
  var req SignalMetricsBatchJobCreateRequest
  if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
    http.Error(w, err.Error(), http.StatusBadRequest)
    return
  }

  job, err := createSignalMetricsBatchJob(req)
  if err != nil {
    http.Error(w, err.Error(), http.StatusInternalServerError)
    return
  }

  w.Header().Set("Content-Type", "application/json")
  if err := json.NewEncoder(w).Encode(job); err != nil {
    http.Error(w, err.Error(), http.StatusInternalServerError)
    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