DelayedPlanningAdapter
This interface helps your Adapter to delay planning a fetch.
This is helpful when the data source you are working with is asynchronous and you have to set up a fetch then check back later to get the data.
This is an extension interface to SourceAdapterForPull. It complements the DELAY FetchStrategy by allowing you to repeatedly call your planFetchAgain() method, each time in a new execution context after some delay, with whatever scope you decide to carry between executions.
If your Adapter returns the DELAY FetchStrategy, it must implement this interface.
Note
Chaining will continue until you return a FetchStrategy other than DELAY from your planFetchAgain() method. Returning DELAY is telling Valence you’re still not ready and you need some more time.
Warning
The very first time planFetch() is called, you can return any FetchStrategy you like. If you return DELAY, this interface comes into effect. Valence will wait for a certain amount of time, then call planFetchAgain(). Note that the normal planFetch() method is never called more than once. After the first planFetch(), all additional attempt to plan will be routed to planFetchAgain(). This is so that you can set up a scope and pass it to yourself over and over, for example the jobId for whatever async process you started in your original planFetch() call.
So, to be clear, an example order of execution might be:
planFetch() [returning DELAY]
–NEW EXECUTION CONTEXT–
planFetchAgain() [returning DELAY again]
–NEW EXECUTION CONTEXT–
planFetchAgain() [returning DELAY again]
–NEW EXECUTION CONTEXT–
planFetchAgain() [returning IMMEDIATE]
fetchRecords() [null scope, per usual IMMEDIATE behavior]
Tip
You can return any FetchStrategy from planFetchAgain() that you would return from planFetch().
Definition
/**
* Implement this interface if your SourceAdapter can't resolve its planning in a single call to planFetch() and needs more time.
*
* Companion interface to the DELAY FetchStrategy.
*/
global interface DelayedPlanningAdapter extends SourceAdapterForPull {
/**
* Called after planFetch() has been called once and returned a DELAY FetchStrategy. This method is then called after
* some amount of time. You can chain this method again and again if you return a DELAY strategy from this method.
*
* Use this if planning your fetch is asynchronous or takes some time so that you can wait to start fetching until you're actually ready.
*
* @param context Information about this Link and the current execution of it.
* @param scope Any additional details the original call to planFetch() gave us for safekeeping
*
* @return The FetchStrategy to use
*/
FetchStrategy planFetchAgain(LinkContext context, Object scope);
}
Tip
Passing a null as your minutes parameter for valence.FetchStrategy.delay(minutes, scope) will let Valence decide how long to wait before calling planFetchAgain(), which will usually be somewhere between 5 seconds and 75 seconds.