Custom Executor
Last updated
Last updated
Clique offers a wide range of tasks officially for various use cases. If these do not meet your requirements, you can create your own executors to cater to specific tasks seamlessly.
To assist developers in quickly implementing a custom executor, Clique provides Rust support. Rust developers can directly use the procedural macros we provide to encapsulate the custom executor. Developers do not need to be concerned with how the executor interacts with the Clique network; they only need to focus on their own computational logic.
First, include the following dependencies in your Rust project:
Clique provides the following procedural macros:
#[namespace(name = ...)]
The namespace
macro ensures that all tasks within the annotated module are grouped under a specific namespace, and the namespace is corresbonding to the name
in the Clique Task Manifest. For example, if the task's name is "clique_httpsRequest," then the namespace should be specified as "clique."
#[task]
The task
macro is used to define a task struct. This macro annotates a struct that represents a task, allowing it to be recognized and managed by the task execution system.
You need to implement the clique::Task
trait for the struct marked with the task
macro, and within the execute
method, implement your actual computational logic. Note that the input and output of the execute
method are Rust struct generated based on the input
and output
section of your Clique Task Manifest file. You can directly use the field name from the manifest to access the corresbonding field in the input / output.
#[clique::async_trait]
This macro is used to annotate the implementation of clique::Task
trait, since this trait is async
#[executor(with(...))]
The executor
macro is used to define an executor struct that can handle the execution of multiple task modules. In the with
field, fill in the name of the module decorated with the namespace
macro. The tasks within these modules will be imported into your custom executor.
Here is an example: