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 method for creating a signal metrics with time series job #77

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

Comments

@youen
Copy link
Member

youen commented Mar 31, 2024

Description

Add a method to the API client for creating a signal metrics with time series job. This will allow users to create jobs that will generate metrics based on time series data.

Request

Method

POST

URL

/jobs/metrics/signal_time_series

Request Parameters

Parameter Description Required Example
kind The kind of job to be created. Yes "signal_metrics_with_time_series"
parameters The parameters for the job. Yes See below

Request Body

{
  "kind": "signal_metrics_with_time_series",
  "parameters": {}
}

Result

Result parameters

Parameter Description
id The ID of the job.
kind The kind of job.
created_at The time at which the job was created.
status The status of the job.
error_message The error message, if any.
traceback The traceback, if any.
result The result of the job, if any.
parameters The parameters of the job.
current_progress The current progress of the job.

Result Body

The result body is a JSON object with the following structure:

{
  "id": "123e4567-e89b-12d3-a456-426655440000",
  "kind": "signal_metrics_with_time_series",
  "created_at": "2022-05-24T16:32:30.123456Z",
  "status": "pending",
  "error_message": null,
  "traceback": null,
  "result": null,
  "parameters": {},
  "current_progress": null
}

Example Curl Request

Request

curl -X POST 'http://localhost:8080/jobs/metrics/signal_time_series' -H 'Content-Type: application/json' -d '{
  "kind": "signal_metrics_with_time_series",
  "parameters": {}
}'

Curl Response

{
  "id": "123e4567-e89b-12d3-a456-426655440000",
  "kind": "signal_metrics_with_time_series",
  "created_at": "2022-05-24T16:32:30.123456Z",
  "status": "pending",
  "error_message": null,
  "traceback": null,
  "result": null,
  "parameters": {},
  "current_progress": null
}

Go server

Struct

type SignalMetricsWithTimeSeriesJobRequest struct {
	Kind         JobKind                        `json:"kind"`
	Parameters   SignalMetricsWithTimeSeriesParams `json:"parameters,omitempty"`
}

Handler

func (s *API) CreateSignalMetricsWithTimeSeriesJob(w http.ResponseWriter, r *http.Request) {
	ctx := context.Background()
	var request SignalMetricsWithTimeSeriesJobRequest

	if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
		http.Error(w, "invalid request body", http.StatusBadRequest)
		return
	}

	if _, err := s.jobs.Create(ctx, job.KindSignalMetricsWithTimeSeries, request.Parameters); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	w.WriteHeader(http.StatusCreated)
}
```req); err != nil {
		h.JSON(w, http.StatusBadRequest, errors.New("invalid request"))
		return
	}

	if err := validation.ValidateStruct(&req); err != nil {
		h.JSON(w, http.StatusBadRequest, errors.New("invalid request"))
		return
	}

	status := JobStatusRunning

	sm := signals.NewSignalMetricsWithTimeSeries(
		req.Parameters.SignalName,
		req.Parameters.TimeSeriesID,
		req.Parameters.StartDate,
		req.Parameters.EndDate,
		req.Parameters.AggregationType,
	)

	j := &Job{
		ID:          uuid.New().String(),
		Kind:        JobKindSignalMetricsWithTimeSeries,
		CreatedAT:   time.Now(),
		Status:      status,
		Parameters:  &req.Parameters,
		Result:      &sm,
		CurrentStep: 0,
	}

	go h.jobExecutor.Execute(j)

	h.JSON(w, http.StatusCreated, j)
}

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