api

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 8 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TriggerResponseResult_name = map[int32]string{
		0: "SUCCESS",
		1: "FAILED",
		2: "UNDELIVERABLE",
	}
	TriggerResponseResult_value = map[string]int32{
		"SUCCESS":       0,
		"FAILED":        1,
		"UNDELIVERABLE": 2,
	}
)

Enum value maps for TriggerResponseResult.

View Source
var File_proto_api_failurepolicy_proto protoreflect.FileDescriptor
View Source
var File_proto_api_job_proto protoreflect.FileDescriptor
View Source
var File_proto_api_list_proto protoreflect.FileDescriptor
View Source
var File_proto_api_trigger_proto protoreflect.FileDescriptor
View Source
var File_proto_counter_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type Counter

type Counter struct {

	// job_partition_id is the parition_id of the job this counter belongs to.
	// Prevents an updated job from inheriting the counter of a previous job with
	// the same name.
	// Doesn't need to be globally unique.
	JobPartitionId uint32 `protobuf:"varint,1,opt,name=job_partition_id,json=jobPartitionId,proto3" json:"job_partition_id,omitempty"`
	// count is the number of times the job has been triggered.
	Count uint32 `protobuf:"varint,2,opt,name=count,proto3" json:"count,omitempty"`
	// last_trigger is the timestamp the job was last triggered. Used to
	// determine the next time the job should be triggered.
	LastTrigger *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=last_trigger,json=lastTrigger,proto3" json:"last_trigger,omitempty"`
	// contains filtered or unexported fields
}

Counter holds counter information for a given job.

func (*Counter) Descriptor deprecated

func (*Counter) Descriptor() ([]byte, []int)

Deprecated: Use Counter.ProtoReflect.Descriptor instead.

func (*Counter) GetCount

func (x *Counter) GetCount() uint32

func (*Counter) GetJobPartitionId

func (x *Counter) GetJobPartitionId() uint32

func (*Counter) GetLastTrigger

func (x *Counter) GetLastTrigger() *timestamppb.Timestamp

func (*Counter) ProtoMessage

func (*Counter) ProtoMessage()

func (*Counter) ProtoReflect

func (x *Counter) ProtoReflect() protoreflect.Message

func (*Counter) Reset

func (x *Counter) Reset()

func (*Counter) String

func (x *Counter) String() string

type FailurePolicy added in v0.3.1

type FailurePolicy struct {

	// policy is the policy to apply when a job fails to trigger.
	//
	// Types that are assignable to Policy:
	//
	//	*FailurePolicy_Drop
	//	*FailurePolicy_Constant
	Policy isFailurePolicy_Policy `protobuf_oneof:"policy"`
	// contains filtered or unexported fields
}

FailurePolicy defines the policy to apply when a job fails to trigger.

func (*FailurePolicy) Descriptor deprecated added in v0.3.1

func (*FailurePolicy) Descriptor() ([]byte, []int)

Deprecated: Use FailurePolicy.ProtoReflect.Descriptor instead.

func (*FailurePolicy) GetConstant added in v0.3.1

func (x *FailurePolicy) GetConstant() *FailurePolicyConstant

func (*FailurePolicy) GetDrop added in v0.3.1

func (x *FailurePolicy) GetDrop() *FailurePolicyDrop

func (*FailurePolicy) GetPolicy added in v0.3.1

func (m *FailurePolicy) GetPolicy() isFailurePolicy_Policy

func (*FailurePolicy) ProtoMessage added in v0.3.1

func (*FailurePolicy) ProtoMessage()

func (*FailurePolicy) ProtoReflect added in v0.3.1

func (x *FailurePolicy) ProtoReflect() protoreflect.Message

func (*FailurePolicy) Reset added in v0.3.1

func (x *FailurePolicy) Reset()

func (*FailurePolicy) String added in v0.3.1

func (x *FailurePolicy) String() string

type FailurePolicyConstant added in v0.3.1

type FailurePolicyConstant struct {

	// interval is the constant delay to wait before retrying the job.
	Interval *durationpb.Duration `protobuf:"bytes,1,opt,name=interval,proto3" json:"interval,omitempty"`
	// max_retries is the optional maximum number of retries to attempt before
	// giving up.
	// If unset, the Job will be retried indefinitely.
	MaxRetries *uint32 `protobuf:"varint,2,opt,name=max_retries,json=maxRetries,proto3,oneof" json:"max_retries,omitempty"`
	// contains filtered or unexported fields
}

FailurePolicyRetry is a policy which retries the job at a consistent interval when the job fails to trigger.

func (*FailurePolicyConstant) Descriptor deprecated added in v0.3.1

func (*FailurePolicyConstant) Descriptor() ([]byte, []int)

Deprecated: Use FailurePolicyConstant.ProtoReflect.Descriptor instead.

func (*FailurePolicyConstant) GetInterval added in v0.3.1

func (x *FailurePolicyConstant) GetInterval() *durationpb.Duration

func (*FailurePolicyConstant) GetMaxRetries added in v0.3.1

func (x *FailurePolicyConstant) GetMaxRetries() uint32

func (*FailurePolicyConstant) ProtoMessage added in v0.3.1

func (*FailurePolicyConstant) ProtoMessage()

func (*FailurePolicyConstant) ProtoReflect added in v0.3.1

func (x *FailurePolicyConstant) ProtoReflect() protoreflect.Message

func (*FailurePolicyConstant) Reset added in v0.3.1

func (x *FailurePolicyConstant) Reset()

func (*FailurePolicyConstant) String added in v0.3.1

func (x *FailurePolicyConstant) String() string

type FailurePolicyDrop added in v0.3.1

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

FailurePolicyDrop is a policy which drops the job tick when the job fails to trigger.

func (*FailurePolicyDrop) Descriptor deprecated added in v0.3.1

func (*FailurePolicyDrop) Descriptor() ([]byte, []int)

Deprecated: Use FailurePolicyDrop.ProtoReflect.Descriptor instead.

func (*FailurePolicyDrop) ProtoMessage added in v0.3.1

func (*FailurePolicyDrop) ProtoMessage()

func (*FailurePolicyDrop) ProtoReflect added in v0.3.1

func (x *FailurePolicyDrop) ProtoReflect() protoreflect.Message

func (*FailurePolicyDrop) Reset added in v0.3.1

func (x *FailurePolicyDrop) Reset()

func (*FailurePolicyDrop) String added in v0.3.1

func (x *FailurePolicyDrop) String() string

type FailurePolicy_Constant added in v0.3.1

type FailurePolicy_Constant struct {
	Constant *FailurePolicyConstant `protobuf:"bytes,2,opt,name=constant,proto3,oneof"`
}

type FailurePolicy_Drop added in v0.3.1

type FailurePolicy_Drop struct {
	Drop *FailurePolicyDrop `protobuf:"bytes,1,opt,name=drop,proto3,oneof"`
}

type Interface added in v0.3.1

type Interface interface {
	// Run is a blocking function that runs the cron instance. It will return an
	// error if the instance is already running.
	// Returns when the given context is cancelled, after doing all cleanup.
	Run(ctx context.Context) error

	// Add adds a job to the cron instance.
	Add(ctx context.Context, name string, job *Job) error

	// Get gets a job from the cron instance.
	Get(ctx context.Context, name string) (*Job, error)

	// Delete deletes a job from the cron instance.
	Delete(ctx context.Context, name string) error

	// DeletePrefixes deletes all jobs with the given prefixes from the cron
	// instance.
	DeletePrefixes(ctx context.Context, prefixes ...string) error

	// List lists all jobs under a given job name prefix.
	List(ctx context.Context, prefix string) (*ListResponse, error)

	// DeliverablePrefixes registers the given Job name prefixes as being
	// deliverable. Any Jobs that reside in the staging queue because they were
	// undeliverable at the time of trigger but whose names match these prefixes
	// will be immediately re-triggered.
	// The returned CancelFunc should be called to unregister the prefixes,
	// meaning these prefixes are no longer delivable by the caller. Duplicate
	// Prefixes may be called together and will be pooled together, meaning that
	// the prefix is still active if there is at least one DeliverablePrefixes
	// call that has not been unregistered.
	DeliverablePrefixes(ctx context.Context, prefixes ...string) (context.CancelFunc, error)
}

Interface is a cron interface. It schedules and manages job which are stored and informed from ETCD. It uses a trigger function to call when a job is triggered. Jobs may be oneshot or recurring. Recurring jobs are scheduled to run at their next scheduled time. Oneshot jobs are scheduled to run once and are removed from the schedule after they are triggered.

type Job

type Job struct {

	// schedule is an optional schedule at which the job is to be run.
	// Accepts both systemd timer style cron expressions, as well as human
	// readable '@' prefixed period strings as defined below.
	//
	// Systemd timer style cron accepts 6 fields:
	// seconds | minutes | hours | day of month | month        | day of week
	// 0-59    | 0-59    | 0-23  | 1-31         | 1-12/jan-dec | 0-6/sun-sat
	//
	// "0 30 * * * *" - every hour on the half hour
	// "0 15 3 * * *" - every day at 03:15
	//
	// Period string expressions:
	// Entry                  | Description                                | Equivalent To
	// -----                  | -----------                                | -------------
	// @every <duration>      | Run every <duration> (e.g. '@every 1h30m') | N/A
	// @yearly (or @annually) | Run once a year, midnight, Jan. 1st        | 0 0 0 1 1 *
	// @monthly               | Run once a month, midnight, first of month | 0 0 0 1 * *
	// @weekly                | Run once a week, midnight on Sunday        | 0 0 0 * * 0
	// @daily (or @midnight)  | Run once a day, midnight                   | 0 0 0 * * *
	// @hourly                | Run once an hour, beginning of hour        | 0 0 * * * *
	Schedule *string `protobuf:"bytes,1,opt,name=schedule,proto3,oneof" json:"schedule,omitempty"`
	// due_time is the optional time at which the job should be active, or the
	// "one shot" time if other scheduling type fields are not provided.
	// Accepts a "point in time" string in the format of RFC3339, Go duration
	// string (therefore calculated from now), or non-repeating ISO8601.
	DueTime *string `protobuf:"bytes,2,opt,name=due_time,json=dueTime,proto3,oneof" json:"due_time,omitempty"`
	// ttl is the optional time to live or expiration of the job.
	// Accepts a "point in time" string in the format of RFC3339, Go duration
	// string (therefore calculated from now), or non-repeating ISO8601.
	Ttl *string `protobuf:"bytes,3,opt,name=ttl,proto3,oneof" json:"ttl,omitempty"`
	// repeats is the optional number of times in which the job should be
	// triggered. If not set, the job will run indefinitely or until expiration.
	Repeats *uint32 `protobuf:"varint,4,opt,name=repeats,proto3,oneof" json:"repeats,omitempty"`
	// metadata is a arbitrary metadata asociated with the job.
	Metadata *anypb.Any `protobuf:"bytes,5,opt,name=metadata,proto3" json:"metadata,omitempty"`
	// payload is the serialized job payload that will be sent to the recipient
	// when the job is triggered.
	Payload *anypb.Any `protobuf:"bytes,6,opt,name=payload,proto3" json:"payload,omitempty"`
	// failure_policy is the optional policy to apply when a job fails to
	// trigger.
	// By default, the failure policy is FailurePolicyConstant with a 1s interval
	// and 3 maximum retries.
	// See `failurepolicy.proto` for more information.
	FailurePolicy *FailurePolicy `protobuf:"bytes,7,opt,name=failure_policy,json=failurePolicy,proto3,oneof" json:"failure_policy,omitempty"`
	// contains filtered or unexported fields
}

Job defines a scheduled rhythmic job stored in the database. Job holds the desired spec of the job, not the current trigger state, held by Counter.

func (*Job) Descriptor deprecated

func (*Job) Descriptor() ([]byte, []int)

Deprecated: Use Job.ProtoReflect.Descriptor instead.

func (*Job) GetDueTime

func (x *Job) GetDueTime() string

func (*Job) GetFailurePolicy added in v0.3.1

func (x *Job) GetFailurePolicy() *FailurePolicy

func (*Job) GetMetadata

func (x *Job) GetMetadata() *anypb.Any

func (*Job) GetPayload

func (x *Job) GetPayload() *anypb.Any

func (*Job) GetRepeats

func (x *Job) GetRepeats() uint32

func (*Job) GetSchedule

func (x *Job) GetSchedule() string

func (*Job) GetTtl

func (x *Job) GetTtl() string

func (*Job) ProtoMessage

func (*Job) ProtoMessage()

func (*Job) ProtoReflect

func (x *Job) ProtoReflect() protoreflect.Message

func (*Job) Reset

func (x *Job) Reset()

func (*Job) String

func (x *Job) String() string

type ListResponse added in v0.3.1

type ListResponse struct {

	// jobs is the list of jobs.
	Jobs []*NamedJob `protobuf:"bytes,1,rep,name=jobs,proto3" json:"jobs,omitempty"`
	// contains filtered or unexported fields
}

ListResponse is returned by the List RPC.

func (*ListResponse) Descriptor deprecated added in v0.3.1

func (*ListResponse) Descriptor() ([]byte, []int)

Deprecated: Use ListResponse.ProtoReflect.Descriptor instead.

func (*ListResponse) GetJobs added in v0.3.1

func (x *ListResponse) GetJobs() []*NamedJob

func (*ListResponse) ProtoMessage added in v0.3.1

func (*ListResponse) ProtoMessage()

func (*ListResponse) ProtoReflect added in v0.3.1

func (x *ListResponse) ProtoReflect() protoreflect.Message

func (*ListResponse) Reset added in v0.3.1

func (x *ListResponse) Reset()

func (*ListResponse) String added in v0.3.1

func (x *ListResponse) String() string

type NamedJob added in v0.3.1

type NamedJob struct {

	// name is the name of the job.
	Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	// job is the scheduled job.
	Job *Job `protobuf:"bytes,2,opt,name=job,proto3" json:"job,omitempty"`
	// contains filtered or unexported fields
}

NamedJob is a job with a name.

func (*NamedJob) Descriptor deprecated added in v0.3.1

func (*NamedJob) Descriptor() ([]byte, []int)

Deprecated: Use NamedJob.ProtoReflect.Descriptor instead.

func (*NamedJob) GetJob added in v0.3.1

func (x *NamedJob) GetJob() *Job

func (*NamedJob) GetName added in v0.3.1

func (x *NamedJob) GetName() string

func (*NamedJob) ProtoMessage added in v0.3.1

func (*NamedJob) ProtoMessage()

func (*NamedJob) ProtoReflect added in v0.3.1

func (x *NamedJob) ProtoReflect() protoreflect.Message

func (*NamedJob) Reset added in v0.3.1

func (x *NamedJob) Reset()

func (*NamedJob) String added in v0.3.1

func (x *NamedJob) String() string

type TriggerFunction added in v0.3.1

type TriggerFunction func(context.Context, *TriggerRequest) *TriggerResponse

TriggerFunction is the type of the function that is called when a job is triggered. The returne TriggerResponse will indicate whether the Job was successfully triggered, the trigger failed, or the Job need to be put into the staging queue.

type TriggerRequest

type TriggerRequest struct {

	// name is the name of the job that was triggered.
	Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	// metadata is the arbitrary metadata associated with the job.
	Metadata *anypb.Any `protobuf:"bytes,2,opt,name=metadata,proto3" json:"metadata,omitempty"`
	// payload is the job payload.
	Payload *anypb.Any `protobuf:"bytes,3,opt,name=payload,proto3" json:"payload,omitempty"`
	// contains filtered or unexported fields
}

TriggerRequest is the request sent to the caller when a job is triggered.

func (*TriggerRequest) Descriptor deprecated

func (*TriggerRequest) Descriptor() ([]byte, []int)

Deprecated: Use TriggerRequest.ProtoReflect.Descriptor instead.

func (*TriggerRequest) GetMetadata

func (x *TriggerRequest) GetMetadata() *anypb.Any

func (*TriggerRequest) GetName

func (x *TriggerRequest) GetName() string

func (*TriggerRequest) GetPayload

func (x *TriggerRequest) GetPayload() *anypb.Any

func (*TriggerRequest) ProtoMessage

func (*TriggerRequest) ProtoMessage()

func (*TriggerRequest) ProtoReflect

func (x *TriggerRequest) ProtoReflect() protoreflect.Message

func (*TriggerRequest) Reset

func (x *TriggerRequest) Reset()

func (*TriggerRequest) String

func (x *TriggerRequest) String() string

type TriggerResponse added in v0.3.1

type TriggerResponse struct {

	// result is the result given by the consumer when trigging the Job.
	Result TriggerResponseResult `protobuf:"varint,1,opt,name=result,proto3,enum=api.TriggerResponseResult" json:"result,omitempty"`
	// contains filtered or unexported fields
}

TriggerResponse is returned by the caller from a TriggerResponse. Signals whether the Job was successfully triggered, the trigger failed, or instead needs to be added to the staging queue due to impossible delivery.

func (*TriggerResponse) Descriptor deprecated added in v0.3.1

func (*TriggerResponse) Descriptor() ([]byte, []int)

Deprecated: Use TriggerResponse.ProtoReflect.Descriptor instead.

func (*TriggerResponse) GetResult added in v0.3.1

func (x *TriggerResponse) GetResult() TriggerResponseResult

func (*TriggerResponse) ProtoMessage added in v0.3.1

func (*TriggerResponse) ProtoMessage()

func (*TriggerResponse) ProtoReflect added in v0.3.1

func (x *TriggerResponse) ProtoReflect() protoreflect.Message

func (*TriggerResponse) Reset added in v0.3.1

func (x *TriggerResponse) Reset()

func (*TriggerResponse) String added in v0.3.1

func (x *TriggerResponse) String() string

type TriggerResponseResult added in v0.3.1

type TriggerResponseResult int32

TriggerResponseResult is indicates the state result from triggering the job by the consumer.

const (
	// SUCCESS indicates that the job was successfully triggered and will be
	// ticked forward according to the schedule.
	TriggerResponseResult_SUCCESS TriggerResponseResult = 0
	// FAILED indicates that the job failed to trigger and is subject to the
	// FailurePolicy.
	TriggerResponseResult_FAILED TriggerResponseResult = 1
	// UNDELIVERABLE indicates that the job should be added to the staging queue
	// as the Job was undeliverable. Once the Job name prefix is marked as
	// deliverable, it will be immediately triggered.
	TriggerResponseResult_UNDELIVERABLE TriggerResponseResult = 2
)

func (TriggerResponseResult) Descriptor added in v0.3.1

func (TriggerResponseResult) Enum added in v0.3.1

func (TriggerResponseResult) EnumDescriptor deprecated added in v0.3.1

func (TriggerResponseResult) EnumDescriptor() ([]byte, []int)

Deprecated: Use TriggerResponseResult.Descriptor instead.

func (TriggerResponseResult) Number added in v0.3.1

func (TriggerResponseResult) String added in v0.3.1

func (x TriggerResponseResult) String() string

func (TriggerResponseResult) Type added in v0.3.1

Jump to

Keyboard shortcuts

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