Custom Executor
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.
Development Tools
To assist developers in quickly implementing a custom executor, Clique provides Rust procedural macro 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 thename
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 thetask
macro, and within theexecute
method, implement your actual computational logic. Note that the input and output of theexecute
method are Rust struct generated based on theinput
andoutput
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 isasync
#[executor(with(...))]
The
executor
macro is used to define an executor struct that can handle the execution of multiple task modules. In thewith
field, fill in the name of the module decorated with thenamespace
macro. The tasks within these modules will be imported into your custom executor.
Here is an example:
Last updated