Reputation: 531
I'm trying to setup a periodic report job. The report shall be created without user interaction and the job shall be scheduled when the application starts.
I have the background service and scheduler working. If I expose the createReport action as a button in the UI, a report is created when the job is triggered the next time. However, I need this report to be created repeatedly and without user interaction.
I guess the question is how to programmatically invoke an action? Moving createReport() to a domain service and calling it in a @PostConstruct annotated method yields an exception (trying to persist the command to IsisCommand). I'm guessing that I have to have some sort of context for the action invocation? Or am I approaching this the wrong way? Thanks!
@Action(command = CommandReification.ENABLED,
commandExecuteIn=CommandExecuteIn.BACKGROUND)
public Command createReport() {
backgroundService.execute(this).generateReport();
return commandContext.getCommand();
}
@Programmatic
public void generateReport() {
....
}
Upvotes: 2
Views: 294
Reputation: 2235
If you simply want to invoke a method repeatedly, there are a couple of options.
The BackgroundService creates and persists a memento of an action invocation to be picked up later (with the isisaddons' isis-command-module providing an out-of-the-box implementation of this... you probably have this configured already).
When a command is persisted, it must wrap an action, ie cannot be annotated with @Programmatic. So that's one thing.
The next is that, since this action is to be repeated continuously, then something must create the next background invocation.
In theory you could use backgroundService.execute(this).createReport(...) as the last method call in the createReport(...); one caveat is that were some recent bug fixes (made but still to be released in 1.13.1) to get this working reliably; see our Kanban board.
An altogether simpler approach might be to ignore the background command service completely and just use AbstractIsisSessionTemplate, and then call from a custom Quartz job, similar to RunBackgroundCommandsJob.
One last thing: in your code example you annotated the action with commandExecuteIn=BACKGROUND. That means that the framework automatically reifies/persists the action as a command... imagine that it is implicitly calling backgroundCommand.execute(this).xxx() for you. There's no need to also make that call within the action implementation itself.
HTH Dan
Upvotes: 3