GitHub

Classes

Tasks & Scheduling

Tasks are for triggering methods after specified amount of seconds.


Tasks

Sometimes you may want to make another method request but don't need back an immediate response. Let's say you have created an order and you would like to send it to Reporting class. You can trigger a method call by setting data.tasks property.

data.tasks property is an array of Task items which looks like this:

export interface Task {
    classId?: string;
    instanceId?: string;
    payload?: any;
    method: string;
    after: number;
}

Below example triggers two different methods, one for the same instance another one to another class' instance.

data.tasks = [
    {
        after: 5,
        method: "someMethod"
    },
    {
        after: 0,
        method: "someOtherMethodOnAnotherClass",
        classId: "OtherClass",
        instanceId: "other-instance-id",
        payload: { foo: 'bar' }
    }
]
  • after : Defined in seconds. You can define a delay for all kinds of methods. This means execute the method after the provided amount of seconds delay. We currently support delays up to 12 hours.
  • method : Name of the method to call.
  • classId (optional) : Name of class. If not given, same classId will be used making this request.
  • instanceId (optional) : Instance id for a class. If not given request will be sent to the same instance making this request.
  • payload (optional) : A payload to send to triggered method. It will be delivered in data.request.body field.

You cannot trigger more than 250 tasks in a single call and each payload cannot be larger than 250KB.


Scheduling

Besides tasks support, Rio also supports crons.

For more details please visit https://docs.retter.io/docs/classes/methods#static

Previous
Calling Methods