MCPcopy
hub / github.com/hatchet-dev/hatchet / Create

Method Create

sdks/go/features/schedules.go:56–102  ·  view source on GitHub ↗

Create creates a new scheduled workflow run.

(ctx context.Context, workflowName string, trigger CreateScheduledRunTrigger)

Source from the content-addressed store, hash-verified

54
55// Create creates a new scheduled workflow run.
56func (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.
105func (s *SchedulesClient) Delete(ctx context.Context, scheduledRunId string) error {

Callers

nothing calls this directly

Calls 7

ApplyNamespaceFunction · 0.92
validateJSON200ResponseFunction · 0.85
StartMethod · 0.65
StatusCodeMethod · 0.65
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected