Help us shape the future of Go! Take the 2026 Go Developer Survey

stepping

package
v0.3.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package stepping walks an Enrollment through its Automation's steps: one operation executes one step of one Enrollment, moves it and queues the job of the next step in the same transaction. The Automations module keeps the Enrollment's state and lifecycle (ADR 0046); it cannot hold the loop because the Tags module imports it. The module holds no raw database client: a job adapter loads the Enrollment's row, builds the Workspace scope from it (the job entry point of ADR 0017) and passes the scope in.

Index

Constants

View Source
const QueueHTTPSteps = "http_steps"

QueueHTTPSteps isolates the HTTP steps of Automations (ADR 0039): an outbound call to a third party can take its whole timeout and be retried for days, so it must neither hold the default queue's automation steps nor the Webhook deliveries' queue.

Variables

This section is empty.

Functions

func Enroll

func Enroll(ctx context.Context, bus *events.Bus, s *ent.Scoped, automationID, contactID int64) (enrolled bool, err error)

Enroll enrolls the Contact in the Automation, once ever (ADR 0046), and queues the job of its first step in the same transaction: a failed queue insert leaves no Enrollment that nothing will move, and a retry starts over. enrolled is false, and nothing is queued, when the Contact was enrolled before or another writer won the race. It is the one way a trigger or a Rule Action starts an Enrollment.

Types

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module executes the steps of Enrollments.

func New

func New(bus *events.Bus, out *outbound.Module, fence automations.Fencer, opts ...Option) *Module

New builds the module. The bus runs a move and the job that follows it in one transaction; out sends an email step and acts as the `system` actor for a tag step; fence orders a send against an exit of the Enrollment.

func (*Module) FailHTTPStep

func (m *Module) FailHTTPStep(ctx context.Context, s *ent.Scoped, runID int64, f automations.Failure) error

FailHTTPStep ends the Enrollment `failed` with the record of the call that could not succeed. An Enrollment that already left `active` (an exit won) or is gone stays as it is.

func (*Module) FinishHTTPStep

func (m *Module) FinishHTTPStep(ctx context.Context, s *ent.Scoped, runID int64, step int) error

FinishHTTPStep moves the Enrollment past its HTTP step and queues the step after it, in one transaction. Nothing happens when the Enrollment no longer stands on step: an exit won while the call was in flight, or an earlier attempt of the call already moved it.

func (*Module) Step

func (m *Module) Step(ctx context.Context, s *ent.Scoped, runID int64, step int) error

Step executes step of the Enrollment runID and queues what follows it, in one transaction with the move. It does nothing, and returns nil, when the Enrollment can no longer take that step: it is erased with its Contact (ADR 0021), has left `active`, or stands elsewhere than step because this job was delivered twice or a competing writer moved it. A step that runs before the Enrollment's recorded resume time queues itself for that time and does nothing else. An email step is one Outbound send under the Automation's Sending source (ADR 0015): the module owns eligibility, the unsubscribe footer and the send record, and Step only turns its Outcome into the Enrollment's next state.

type Option

type Option func(*Module)

Option configures the module.

func WithClock

func WithClock(now func() time.Time) Option

WithClock replaces the wall clock the module reads to honour an Enrollment's resume time and to time a wait.

type RunHTTPStepArgs

type RunHTTPStepArgs struct {
	RunID int64 `json:"run_id"`
	Step  int   `json:"step"`
}

RunHTTPStepArgs is the job that makes the call of one HTTP step of one Enrollment, on a queue of its own. Like RunStepArgs it names the step it expects the Enrollment to be at, and carries the run id for Erasure.

func (RunHTTPStepArgs) InsertOpts

func (RunHTTPStepArgs) InsertOpts() river.InsertOpts

InsertOpts puts the call on its own queue with the retry horizon of a hook. The job is unique by its args: an HTTP step makes no move of the Enrollment, so a step job delivered again while the call is in flight would queue a second one and the receiver would be called twice.

func (RunHTTPStepArgs) Kind

func (RunHTTPStepArgs) Kind() string

type RunStepArgs

type RunStepArgs struct {
	RunID int64 `json:"run_id"`
	Step  int   `json:"step"`
}

RunStepArgs is the job that executes one step of one Enrollment. Step is the position the job expects the Enrollment to be at: a job delivered again after its step moved the Enrollment finds it elsewhere and ends quietly. The args carry the run id, so Erasure can delete a queued step by it (ADR 0021): renaming `run_id` breaks that purge.

func (RunStepArgs) Kind

func (RunStepArgs) Kind() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL