examples

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SimpleExampleTask

type SimpleExampleTask struct {
	// All tasks should start by being composed by the BaseTask
	*tasks.BaseTask
	// everything from here onwards are fields that are unique to this task. If
	// a field is exposed it will be serialized, persisted and restored during
	// eventual crashes.
	Foo uint64
}

SimpleExampleTask executes a simple example task

func NewSimpleExampleTask

func NewSimpleExampleTask(start uint64, end uint64) *SimpleExampleTask

OPTIONAL: Auxiliary function to create this task

func (*SimpleExampleTask) Execute

Execute executes the task business logic (main action). This function may or may not call the layer 1 smart contracts. In case this function doesn't call the smart contracts it should return nil, otherwise it should return the transaction. ALWAYS USE THE CTX THAT IT'S PASSED TO THIS FUNCTION. IN CASE YOU NEED ANOTHER CONTEXT (E.G WithTimeout) CREATE THE CONTEXT FROM THE CTX PASSED TO THIS FUNCTION. ALWAYS MAKE SURE THAT THERE'S NO POSSIBILITY OF INFINITE LOOP THAT DOESN'T CHECK THE CTX IN HERE.

func (*SimpleExampleTask) Prepare

func (t *SimpleExampleTask) Prepare(ctx context.Context) *tasks.TaskErr

Prepare prepares for work to be done by the task. Put in here any preparation logic to execute the task action. E.g preparing a snapshot, computing ethdkg data to send to smart contracts. This function should be simple. ALWAYS USE THE CTX THAT IT'S PASSED TO THIS FUNCTION. IN CASE YOU NEED ANOTHER CONTEXT (E.G WithTimeout) CREATE THE CONTEXT FROM THE CTX PASSED TO THIS FUNCTION. ALWAYS MAKE SURE THAT THERE'S NO POSSIBILITY OF INFINITE LOOP THAT DOESN'T CHECK THE CTX IN HERE.

func (*SimpleExampleTask) ShouldExecute

func (t *SimpleExampleTask) ShouldExecute(ctx context.Context) (bool, *tasks.TaskErr)

ShouldExecute checks if it makes sense to execute the task. This function should contain the logic to see if the actions were already performed (by someone else or by this node) or if the execute function succeeded (e.g the data was committed to a layer 1 smart contract state). This function will be used to check if the execute operation succeeded in addition to the receipt of the txn created by the Execute method (in case an execution happened). This function should return true in case we should execute or false if the completion requirements were fulfilled and there's no need to execute. ALWAYS USE THE CTX THAT IT'S PASSED TO THIS FUNCTION. IN CASE YOU NEED ANOTHER CONTEXT (E.G WithTimeout) CREATE THE CONTEXT FROM THE CTX PASSED TO THIS FUNCTION. ALWAYS MAKE SURE THAT THERE'S NO POSSIBILITY OF INFINITE LOOP THAT DOESN'T CHECK THE CTX IN HERE.

Jump to

Keyboard shortcuts

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