Create creates a new scheduled workflow run.
(ctx context.Context, workflowName string, trigger CreateScheduledRunTrigger)
| 54 | |
| 55 | // Create creates a new scheduled workflow run. |
| 56 | func (s *SchedulesClient) Create(ctx context.Context, workflowName string, trigger CreateScheduledRunTrigger) (*rest.ScheduledWorkflows, error) { |
| 57 | tracer := otel.Tracer("github.com/hatchet-dev/hatchet/sdks/go") |
| 58 | ctx, span := tracer.Start(ctx, hatchetotel.SpanScheduleWorkflow, |
| 59 | trace.WithSpanKind(trace.SpanKindProducer), |
| 60 | trace.WithAttributes( |
| 61 | attribute.String(hatchetotel.AttrInstrumentor, hatchetotel.AttrInstrumentorValue), |
| 62 | attribute.String(hatchetotel.AttrWorkflowName, workflowName), |
| 63 | attribute.String(hatchetotel.AttrTriggerAt, trigger.TriggerAt.Format(time.RFC3339)), |
| 64 | ), |
| 65 | ) |
| 66 | defer span.End() |
| 67 | |
| 68 | workflowName = client.ApplyNamespace(workflowName, s.namespace) |
| 69 | |
| 70 | var priority *int32 |
| 71 | |
| 72 | if trigger.Priority != nil { |
| 73 | priorityInt := int32(*trigger.Priority) |
| 74 | priority = &priorityInt |
| 75 | } |
| 76 | |
| 77 | request := rest.ScheduleWorkflowRunRequest{ |
| 78 | Input: trigger.Input, |
| 79 | AdditionalMetadata: trigger.AdditionalMetadata, |
| 80 | TriggerAt: trigger.TriggerAt, |
| 81 | Priority: priority, |
| 82 | } |
| 83 | |
| 84 | resp, err := s.api.ScheduledWorkflowRunCreateWithResponse( |
| 85 | ctx, |
| 86 | s.tenantId, |
| 87 | workflowName, |
| 88 | request, |
| 89 | ) |
| 90 | if err != nil { |
| 91 | span.SetStatus(otelcodes.Error, err.Error()) |
| 92 | return nil, errors.Wrap(err, "failed to create scheduled workflow run") |
| 93 | } |
| 94 | |
| 95 | if err := validateJSON200Response(resp.StatusCode(), resp.Body, resp.JSON200); err != nil { |
| 96 | span.SetStatus(otelcodes.Error, err.Error()) |
| 97 | return nil, err |
| 98 | } |
| 99 | |
| 100 | span.SetStatus(otelcodes.Ok, "") |
| 101 | return resp.JSON200, nil |
| 102 | } |
| 103 | |
| 104 | // Delete removes a scheduled workflow run. |
| 105 | func (s *SchedulesClient) Delete(ctx context.Context, scheduledRunId string) error { |
nothing calls this directly
no test coverage detected