Repository navigation
Expand file tree
/
Copy pathhandler.go
More file actions
65 lines (49 loc) · 2.29 KB
/
Copy pathhandler.go
File metadata and controls
65 lines (49 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package runnerq
import (
"context"
"encoding/json"
"github.com/google/uuid"
)
// ActivityContext is provided to activity handlers during execution.
type ActivityContext struct {
// ActivityID is the unique identifier for this activity instance.
ActivityID uuid.UUID
// ActivityType is the type of activity being executed.
ActivityType string
// RetryCount is the current retry attempt number (0 for first execution).
RetryCount uint32
// Metadata is custom metadata associated with the activity.
Metadata map[string]string
// Ctx is the Go context for cancellation and deadline propagation.
Ctx context.Context
// ActivityExecutor allows executing other activities from within a handler.
// Spawns made through this executor are tagged as children of this activity.
ActivityExecutor ActivityExecutor
// ParentActivityID is the direct parent of this activity, if any.
ParentActivityID *uuid.UUID
// RootActivityID is the root of the lineage tree this activity belongs to.
// For root activities, RootActivityID equals ActivityID.
RootActivityID uuid.UUID
// Depth is the lineage depth of this activity (0 for roots).
Depth uint16
}
// ActivityHandler is the interface that all activity handlers must implement.
// Implementations should be safe for concurrent use.
type ActivityHandler interface {
// ActivityType returns the activity type string this handler processes.
ActivityType() string
// Handle processes the activity with the given payload and context.
// Returns:
// (result, nil) - completed successfully, result may be nil
// (nil, RetryError) - failed but should be retried
// (nil, NonRetryError)- failed permanently
Handle(ctx ActivityContext, payload json.RawMessage) (json.RawMessage, error)
// OnDeadLetter is called when an activity enters the dead letter state.
// The default behavior (if not overridden by embedding DefaultDeadLetterHandler) is a no-op.
OnDeadLetter(ctx ActivityContext, payload json.RawMessage, errorMsg string)
}
// DefaultDeadLetterHandler provides a no-op OnDeadLetter implementation.
// Embed this in your handler struct if you don't need dead letter handling.
type DefaultDeadLetterHandler struct{}
// OnDeadLetter is a no-op implementation.
func (DefaultDeadLetterHandler) OnDeadLetter(_ ActivityContext, _ json.RawMessage, _ string) {}