Scripting Guide > Programming Methods > Schedule Actions
发布日期: 09/18/2023

Schedule Actions

A Schedule() function lets you set up a JSL script to be executed some number of seconds later.

Schedule( 15, Print( "hello" ) );

Figure 8.6 JMP Scheduler 

JMP Scheduler

A Scheduler window shows the time until the next event and has buttons for restarting (Go) or stopping (Stop) the schedule. Its pop-up menu has a command Show Schedule, which echoes the current schedule to the log. For example, if you checked the schedule several times during the “hello” example, you would see something like this:

Scheduled at 11.55000000000018 :Print("hello")

Scheduled at 4.716666666666697 :Print("hello")

Scheduled at 3.083333333333485 :Print("hello")

The script might also be a name referring to a stored expression. For example, try submitting this script, which calls itself:

quickieScript = Expr(
	Show( "Hi there" );
	Schedule( 15, quickieScript );
);
quickieScript;

This script should show the string “Hi there” in a log window after 15 seconds, and reschedule itself for another 15 seconds, continuing until the Stop button is clicked.

More typically, in a production setting you might want to set up a schedule like this:

FifteenMinuteCheck = Expr(
	Show( "Checking data" );
	Open( "my file", options... );
	distribution( Column( column1 ), capability( spec limits ) );
	Schedule( 15 * 60, FifteenMinuteCheck );
);
FifteenMinuteCheck;

Schedule() initiates an event queue, but once it has the event queued, JMP proceeds with the next statement in the script. For example, the following has results that might surprise you:

Schedule( 3, Print( "one" ) );
Print( "two" );

"two"

"one"

If you want the script to wait until the scheduled events are finished before proceeding, one solution would be to use Wait( ) with a suitable pause. Another is to embed the subsequent actions into the schedule queue. Schedule() accepts a series of arguments to queue many events in sequence. Each event is a separate call to the schedule. Each event time is an absolute time relative to “now” (or the instant that Go is clicked). Therefore, the following sequence finishes in five seconds, not in twelve:

Schedule( 3, Print( "hello" ) );
Schedule( 4, Print( ", world" ) );
Schedule( 5, Print( "--bye" ) );

To cancel all events in a schedule queue, use Clear Schedule.

scheduler[1] << Clear Schedule( );

Note: It is not possible to create multiple threads using Schedule.

Table 8.8 Schedule commands

Message

Syntax

Explanation

Schedule

sc=Schedule(n, script)

Queues an event to run the script after n seconds.

Clear Schedule

sc<<Clear Schedule()

Cancels all events in a schedule queue.

需要更多信息?有问题?从 JMP 用户社区得到解答 (community.jmp.com).