Re: Scheduled command fails with "session is closed" after client session closed.
JB, In my example the command is generating a report using command line parameters. I can see use cases where schedule command perform other repetitive tasks requiring parameter input. That said, this may be an edge case with many workarounds or better implementations. I will be using is a cron job that launches bin/client with the desired command. Paul Spencer > On May 17, 2022, at 2:20 AM, Jean-Baptiste Onofré wrote: > > Hi Paul, > > if your command uses some session resources (like stream), it's normal > as the session is closed when you quit the shell. > > For mail reporting, it's better to create a service that you trigger > with a command (one shot) or with the scheduled (trigger/cron). > > Regards > JB > > On Mon, May 16, 2022 at 7:20 PM Paul Spencer > wrote: >> >> Karaf 4.3.6 >> >> I have scheduled a command to run on a cron schedule, but the command fails >> with "java.lang.IllegalStateException: session is closed" after I exit the >> Karaf client session. The command will only run in the client session >> scheduling the command. >> >> Since command execution can be schedule, I would expect the client session >> scheduling the command would not be required for each execution. >> >> What is I doing wrong? >> >> >> *** >> * Command to schedule the execution of foo:emailReport at 5PM >> ** >> karaf@root()> scheduler:schedule-command --cron "0 0 17 * * ?" >> "foo:emailReport -r j...@example.com &" >> karaf@root()> scheduler:list >> Name │ Schedule >> ──┼─── >> foo:emailReport -r j...@example.com │ cron(0 0 17 * * ?) >> >> *** >> * karaf.log >> *** >> 2022-05-15T17:00:00,025 | WARN | Karaf_Worker-5 | ScriptJob >> | 80 - org.apache.karaf.scheduler.core - 4.3.6 | Error executing >> scheduled command foo:emailReport -r j...@example.com & >> java.lang.IllegalStateException: session is closed >>at >> org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:171) >> ~[?:?] >>at >> org.apache.karaf.shell.impl.console.ConsoleSessionImpl.execute(ConsoleSessionImpl.java:496) >> ~[?:?] >>at >> org.apache.karaf.scheduler.command.support.CommandJob.execute(CommandJob.java:40) >> [!/:?] >>at >> org.apache.karaf.scheduler.core.QuartzJobExecutor.execute(QuartzJobExecutor.java:58) >> [!/:?] >>at org.quartz.core.JobRunShell.run(JobRunShell.java:202) [!/:?] >>at >> org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) >> [!/:?] >> 2022-05-15T17:03:41,930 | INFO | Karaf_Worker-6 | >> ServiceRequestEmailReceiver | 152 - >> com.alexanderpest.bugdata.msg-email-receiver - 2.0.2 | Message count = 554 >> >> >> karaf@root()> scheduler:list >> Name │ Schedule >> ──┼─── >> foo:emailReport -r j...@example.com & │ cron(0 0 17 * * ?) >> >> >> Paul Spencer
Re: scheduled command job fails with "java.lang.IllegalStateException: A job is already in foreground"
Hi, It's the expected behavior as only one command can run in foreground per session (the same as if you are running the command yourself in the shell). Maybe it's not clear enough in the documentation, I can improve that. Regards JB On Mon, May 16, 2022 at 8:10 PM Paul Spencer wrote: > > Karaf 4.3.6 > > If more then one command is schedule to run in the foreground, the some of > the command will fail to run with "java.lang.IllegalStateException: A job is > already in foreground". Command that are scheduled to run in the background > do not have this issue. > > Is this the intended behavior? > > Please update the documentation, > https://karaf.apache.org/manual/latest/#_schedule_a_command, on running jobs > in the background. > Where job runs Command to schedule job > --- > --- > Foreground scheduler:schedule-command --cron "0 0/1 * * * ?" "http:list" > Background scheduler:schedule-command --cron "0 0/1 * * * ?" "http:list > &" > > > > *** > * Scheduling the commands to run in the foreground > *** > karaf@root()> scheduler:schedule-command --cron "0 0/1 * * * ?" "http:list" > karaf@root()> scheduler:schedule-command --cron "0 0/1 * * * ?" > "http:proxy-list" > karaf@root()> scheduler:list > Name │ Schedule > ─┼── > bugdataEmailReceiver.165 │ at(2022-05-16T12:22:05.378-04:00, -1, 30) > http:proxy-list │ cron(0 0/1 * * * ?) > http:list│ cron(0 0/1 * * * ?) > > karaf@root()> ID │ Servlet │ Servlet-Name │ State │ Alias │ Url > ───┼──┼──┼─┼───┼─ > 86 │ Whiteboard$1 │ cxf-servlet │ Deployed│ │ [/*] > > *** > * karaf.log > *** > 13:40:00.023 WARN [Karaf_Worker-22] Error executing scheduled command > http:proxy-list > java.lang.IllegalStateException: A job is already in foreground > at > org.apache.felix.gogo.runtime.CommandSessionImpl$JobImpl.foreground(CommandSessionImpl.java:677) > ~[?:?] > at > org.apache.felix.gogo.runtime.CommandSessionImpl$JobImpl.start(CommandSessionImpl.java:794) > ~[?:?] > at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:300) > ~[?:?] > at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:169) > ~[?:?] > at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:149) > ~[?:?] > at > org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:179) > ~[?:?] > at > org.apache.karaf.shell.impl.console.ConsoleSessionImpl.execute(ConsoleSessionImpl.java:496) > ~[?:?] > at > org.apache.karaf.scheduler.command.support.CommandJob.execute(CommandJob.java:40) > [!/:?] > at > org.apache.karaf.scheduler.core.QuartzJobExecutor.execute(QuartzJobExecutor.java:58) > [!/:?] > at org.quartz.core.JobRunShell.run(JobRunShell.java:202) [!/:?] > at > org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) > [!/:?] > > *** > * Scheduling the commands to run in the background > *** > karaf@root()> scheduler:schedule-command --cron "0 0/1 * * * ?" "http:list &" > karaf@root()> scheduler:schedule-command --cron "0 0/1 * * * ?" > "http:proxy-list &" > karaf@root()> > > > > [1] background http:proxy-list > karaf@root()> URL │ ProxyTo │ Balancing Policy > ┼─┼─ > [1] donehttp:proxy-list > karaf@root()> > > > > [1] background http:list > karaf@root()> ID │ Servlet │ Servlet-Name │ State │ Alias │ Url > ───┼──┼──┼─┼───┼─ > 86 │ Whiteboard$1 │ cxf-servlet │ Deployed│ │ [/*] > [1] donehttp:list > karaf@root()> > > Paul Spencer >
Re: cut/paste error in the logger definition of the Scheduler's CommandJob?
Good catch, I gonna fix that. Regards JB On Mon, May 16, 2022 at 8:08 PM Paul Spencer wrote: > > Looks like a cut/paste error in the logger definition for Scheduler's > CommandJob. > > https://github.com/apache/karaf/blob/main/scheduler/src/main/java/org/apache/karaf/scheduler/command/support/CommandJob.java > > public class CommandJob implements Job { > > private static final Logger LOGGER = > LoggerFactory.getLogger(ScriptJob.class); > > Paul Spencer > >
Re: Scheduled command fails with "session is closed" after client session closed.
Hi Paul, if your command uses some session resources (like stream), it's normal as the session is closed when you quit the shell. For mail reporting, it's better to create a service that you trigger with a command (one shot) or with the scheduled (trigger/cron). Regards JB On Mon, May 16, 2022 at 7:20 PM Paul Spencer wrote: > > Karaf 4.3.6 > > I have scheduled a command to run on a cron schedule, but the command fails > with "java.lang.IllegalStateException: session is closed" after I exit the > Karaf client session. The command will only run in the client session > scheduling the command. > > Since command execution can be schedule, I would expect the client session > scheduling the command would not be required for each execution. > > What is I doing wrong? > > > *** > * Command to schedule the execution of foo:emailReport at 5PM > ** > karaf@root()> scheduler:schedule-command --cron "0 0 17 * * ?" > "foo:emailReport -r j...@example.com &" > karaf@root()> scheduler:list > Name │ Schedule > ──┼─── > foo:emailReport -r j...@example.com │ cron(0 0 17 * * ?) > > *** > * karaf.log > *** > 2022-05-15T17:00:00,025 | WARN | Karaf_Worker-5 | ScriptJob > | 80 - org.apache.karaf.scheduler.core - 4.3.6 | Error executing > scheduled command foo:emailReport -r j...@example.com & > java.lang.IllegalStateException: session is closed > at > org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:171) > ~[?:?] > at > org.apache.karaf.shell.impl.console.ConsoleSessionImpl.execute(ConsoleSessionImpl.java:496) > ~[?:?] > at > org.apache.karaf.scheduler.command.support.CommandJob.execute(CommandJob.java:40) > [!/:?] > at > org.apache.karaf.scheduler.core.QuartzJobExecutor.execute(QuartzJobExecutor.java:58) > [!/:?] > at org.quartz.core.JobRunShell.run(JobRunShell.java:202) [!/:?] > at > org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) > [!/:?] > 2022-05-15T17:03:41,930 | INFO | Karaf_Worker-6 | > ServiceRequestEmailReceiver | 152 - > com.alexanderpest.bugdata.msg-email-receiver - 2.0.2 | Message count = 554 > > > karaf@root()> scheduler:list > Name │ Schedule > ──┼─── > foo:emailReport -r j...@example.com & │ cron(0 0 17 * * ?) > > > Paul Spencer