Skip to content
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion x/cron/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (

var (
LabelExecuteReadySchedules = "execute_ready_schedules"
LabelExecuteCronSchedule = "execute_cron_schedule"
LabelExecuteCronContract = "execute_cron_contract"
LabelScheduleCount = "schedule_count"
LabelScheduleExecutionsCount = "schedule_executions_count"

Expand Down Expand Up @@ -67,7 +69,7 @@ func (k *Keeper) Logger(ctx sdk.Context) log.Logger {
// ExecuteReadySchedules gets all schedules that are due for execution (with limit that is equal to Params.Limit)
// and executes messages in each one
func (k *Keeper) ExecuteReadySchedules(ctx sdk.Context, executionStage types.ExecutionStage) {
telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), LabelExecuteReadySchedules)
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), LabelExecuteReadySchedules)
schedules := k.getSchedulesReadyForExecution(ctx, executionStage)

for _, schedule := range schedules {
Expand Down Expand Up @@ -182,12 +184,14 @@ func (k *Keeper) getSchedulesReadyForExecution(ctx sdk.Context, executionStage t
func (k *Keeper) executeSchedule(ctx sdk.Context, schedule types.Schedule) error {
// Even if contract execution returned an error, we still increase the height
// and execute it after this interval
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), LabelExecuteCronSchedule, schedule.Name)
schedule.LastExecuteHeight = uint64(ctx.BlockHeight()) //nolint:gosec
k.storeSchedule(ctx, schedule)

cacheCtx, writeFn := ctx.CacheContext()

for idx, msg := range schedule.Msgs {
startTimeContract := time.Now()
executeMsg := wasmtypes.MsgExecuteContract{
Sender: k.accountKeeper.GetModuleAddress(types.ModuleName).String(),
Contract: msg.Contract,
Expand All @@ -205,6 +209,7 @@ func (k *Keeper) executeSchedule(ctx sdk.Context, schedule types.Schedule) error
)
return err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case of error, you are missing both telemetry.ModuleMeasureSince calls, it's better to use defer

}
defer telemetry.ModuleMeasureSince(types.ModuleName, startTimeContract, LabelExecuteCronContract, schedule.Name, msg.Contract)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, suppose we have two schedules:A and B. A gets called first, B is second.
Doesn't this defer call mean, that a measurement for A call contains a time consumption of the B call?
Because the ModuleMeasureSince is called only in the end of the whole execution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resloved

}

// only save state if all the messages in a schedule were executed successfully
Expand Down
Loading