Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

 

@Scheduled

Specifies

Table of Contents

 

 

Creating Scheduled Functions

@Scheduled

Function annotation which specifies a scheduled task to run at a certain interval

 

info

.

Code Block
languagejava
linenumberstrue
//
 Run at 2:15 AM every day
 Run at 2:15 AM every day
@Scheduled("
15 2 * * 
15 2 * * *")

void
 foobar
 foobar()
 
 {
 
 ...
 }
  •  
  • // Run at 06:00 every week-day  (days 1 to 5)
  • @Scheduled("0 6 * * 1
     }
     
    // Run at 06:00 every week-day  (days 1 to 5)
    @Scheduled("0 6 * * 1-5")
    
    void
     foobar
     foobar()
     
     {
     
     ...
     
     }
    
    
    // Run every ten minutes
    
    @Scheduled("*/
    10 
    10 *
     
     *
     
     *
     
     *")
    
    void
     foobar
     foobar()
     
     {
     
     ...
     
     }

     

    To summarize the schedule string format: 

    "minute hour day-of-month month day-of-week"

     

     

     

    Inspecting Scheduled Function Results

    The __scheduled_function_result__ Built-in Object

    The __scheduled_function_result__ object represents scheduled function results from Helium that are duplicated in the app schema for easy access to app developers. Records belonging to this object can be queried using the standard selectors. Note that this feature is to be deployed as part of Helium 1.5. The object declaration is shown below:

    Code Block
    languagejava
    linenumberstrue
    @NotTracked
    persistent object __scheduled_function_result__ {
        datetime datetimestampStarted;
        datetime datetimestampFinished;
        string qualifiedName;
        string schedule;
        string error;
        string stackTrace;
        bool success;
    }

     

    @OnScheduledFunctionResultUpdate

    Used to annotate a function that will be used as a callback function by Helium when there is any update on scheduled function results. The annotation cannot be used in conjunction with other function annotations and the function must take exactly one parameter of type __scheduled_function_result__. Note that this feature will be deployed as part of Helium 1.5. The example below demonstrates the use of this annotation.

    Code Block
    languagejava
    linenumberstrue
    @OnScheduledFunctionResultUpdate
    void scheduledFunctionResultUpdateCallback(__scheduled_function_result__ scheduledFunctionResult) {
        if(scheduledFunctionResult.success == false) {
            FailedScheduledFunction failedScheduledFunction = FailedScheduledFunction:new();
            failedScheduledFunction.failureRecordedOn = Mez:now();
            failedScheduledFunction.scheduledFunctionResultId = scheduledFunctionResult._id;
            failedScheduledFunction.save();
        }
    }

     

    Note that duplicating the data from the __scheduled_function_result__ object in the above code snippet is done purely for demonstration purposes. Records from this object can be queried directly without needing to duplicate the data into a custom object.

     

     

     

    Excerpt
    hiddentrue

    @Scheduled | __scheduled_function_result__ | @OnScheduledFunctionResultUpdate