We have updated the timerTool to core in v0.2.0!
Features
-
Schedule timer events with custom parameters
-
Synchronous and asynchronous action support
-
Automatic timer reconstitution after upgrades
-
Safety timers for trap recovery
-
Automatic initialization via ClassPlus
The new Repo is at: GitHub - icdevsorg/timerTool: manage and recover timers in motoko
or mops add timer-tool
The most interesting new feature is mix-in support:
import TT “mo:timer-tool”;
import TTMixin “mo:timer-tool/TimerToolMixin”;
import ClassPlus “mo:class-plus”;
import Principal “mo:core/Principal”;
import Star “mo:star/star”;
shared ({ caller = \_owner }) persistent actor class MyCanister() = this {
transient let canisterId = Principal.fromActor(this);
transient let classPlus = ClassPlus.ClassPlusInitializationManager(\_owner, canisterId, true);
// Include the TimerTool mixin
include TTMixin({
config = {
org_icdevs_class_plus_manager = classPlus;
args = null;
pullEnvironment = ?(func() : TT.Environment {
{
advanced = null;
syncUnsafe = null;
reportExecution = null;
reportError = null;
reportBatch = null;
};
});
onInitialize = ?(func(tt: TT.TimerTool) : async\* () {
// Register your handlers here
tt.registerExecutionListenerSync(?“myTask”, handleMyTask);
});
};
caller = \_owner;
canisterId = canisterId;
});
// Your handler
private func handleMyTask(id: TT.ActionId, action: TT.Action) : TT.ActionId {
// Decode params and process
let ?data : ?Nat = from_candid(action.params) else return id;
// Do work…
id;
};
// Schedule a task
public shared func scheduleTask(executeAt: Nat, data: Nat) : async Nat {
let actionId = org_icdevs_timer_tool.setActionSync(executeAt, {
actionType = “myTask”;
params = to_candid(data);
});
actionId.id;
};
};
See more at the repo. Fork, contribute, and send pull requests.