CGI-FR / CGI-FR/SIGO

[FEAT][API] Create signal metrics job

Open
#76 0 comments 0 reactions 0 assignees View on GitHub
api octopize
Dominant language
Go
Stars
6
Forks
0
PR merge metrics
No merged PRs in 30d

Description

## 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
```json
{
"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
```json
{
"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
```bash
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
```bash
{
"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
```go
type CreateSignalMetricsJobRequest struct {
Kind JobKind `json:"kind"`
Parameters SignalMetricsParametersRequest `json:"parameters"`
}
```

### Handler
```go
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

- [Jobs.create_signal_metrics_job](https://github.com/octopize/avatar-python/blob/0.6.2/avatars/api.py#L583)
- [SignalMetricsJobCreate](https://github.com/octopize/avatar-python/blob/0.6.2/avatars/api.py#L583)
- [SignalMetricsJob](https://github.com/octopize/avatar-python/blob/0.6.2/avatars/api.py#L583)

## Automated Issue Details

Dear visitor,

This issue has been automatically generated from the Octopize project [avatar-python](https://github.com/octopize/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

Contributor guide

Open the contributing guide

Research direction

Start with the CreateSignalMetricsJob handler and the linked Jobs.create_signal_metrics_job, SignalMetricsJobCreate, and SignalMetricsJob references. Trace how the Go server creates other jobs, then verify that POST /jobs/metrics/signal accepts the documented parameters and returns the specified pending job response.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.