Extend Task Scheduler
Overview
Extend Task Scheduler enables you to define tasks with custom logic within your Extend app and run them at scheduled times. If you are already familiar with cron, you will find scheduling task execution with Extend Task Scheduler straightforward.
Extend Task Scheduler is available only in the Extend Service Extension app.
Create a task containing custom logic in your Extend Service Extension app
- Go
-
In your Extend app project, create
pkg/proto/generic/task_scheduler/v1folder and put task_scheduler.proto there. -
Run
make prototo generate consumer client code fromtask_scheduler.proto. -
Implement your custom logic in
OnJobTriggeredhandler.package service
import (
"io"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
ts "extend-custom-task-service/pkg/pb/generic/task_scheduler/v1"
)
type TaskSchedulerServiceImpl struct {
ts.UnimplementedTaskSchedulerServiceServer
myService *MyServiceServerImpl
}
func NewTaskSchedulerService(myService *MyServiceServerImpl) *TaskSchedulerServiceImpl {
return &TaskSchedulerServiceImpl{
myService: myService,
}
}
func (s *TaskSchedulerServiceImpl) OnJobTriggered(
stream grpc.BidiStreamingServer[ts.ExecutionContext, ts.Response],
) error {
for {
// Receive ExecutionContext from the stream
execCtx, err := stream.Recv()
if err == io.EOF {
// Client closed the stream
return nil
}
if err != nil {
logrus.Errorf("Error receiving ExecutionContext: %v", err)
return err
}
// Handle different message types
switch execCtx.MessageType {
case ts.MessageType_TASK_START:
// Increment task execution count when a task starts
s.myService.IncrementTaskExecutionCount()
logrus.Infof("Task started with cron expression: %s", execCtx.CronExpression)
case ts.MessageType_HEART_BEAT:
// Handle heartbeat - just log it
logrus.Infof("Received heartbeat with cron expression: %s", execCtx.CronExpression)
default:
logrus.Warnf("Unknown message type: %v", execCtx.MessageType)
}
// Send a response back
response := &ts.Response{}
if err := stream.Send(response); err != nil {
logrus.Errorf("Error sending response: %v", err)
return err
}
}
} -
Register the handler.
taskSchedulerService := service.NewTaskSchedulerService(myServiceServer)
ts.RegisterTaskSchedulerServiceServer(s, taskSchedulerService)
Set task execution schedules
-
On the
App Detailspage of your Extend Service Extension app, go to theTask Schedulertab, and click theCreate Taskbutton.
-
Enter a task name, a cron schedule, and the task's start and end dates. The task will run according to the specified cron schedule for as long as it remains within this date range.

-
You can create multiple tasks, as well as temporarily disable or delete any existing tasks.

Make sure that your Extend Service Extension app, which contains the task for the Task Scheduler, is running: Otherwise, a warning will appear and the scheduled task may not run.

Review task execution history
-
On the
App Detailspage of your Extend Service Extension app, go to theTask Schedulertab, and click the name of the task you want to review.
-
You can view the task's execution history, status, duration, and associated logs. You can also run the task manually at any time by clicking
Run Task Nowbutton, or update its configuration by clickingEdit Taskbutton.
Samples
The sample Extend Service Extension app below includes a task with custom logic that can be triggered by the Extend Task Scheduler.
- Go
git clone https://github.com/AccelByte/extend-service-extension-with-task-scheduler-go.git