Addon objects lifecycle unexpected behavior

We are developing an add-on (app) to Jira Server using RefApp template. It establishes a persistent web-socket connection after installation and reconnects by JobRunner job scheduled to send heartbeat every minute.
There are two major issues:

  1. the websocket connection is established reliably only after add-on installation. Disable/Enable should trigger the same logic (PluginLifeCycleEventHandler.onInstalled), but sometimes does not and it’s very inconvenient
  2. after add-on is uninstalled and removed from Jira Server instance, the above mentioned JobRunner may still trigger although there is a scheduler.unscheduleJob(this.job); in JobRunner.destroy override. It appears it is not invoked sometimes during add-on uninstallation. Moreover, rarely it starts flooding to log every second.

The question is - is there some sort of detailed documentation on add-on and its created objects lifecycle? Is there any way to ensure code written in lifecycle hooks is always executed? Thanks in advance for the response.

1 Like

Do you use com.atlassian.sal.api.lifecycle.LifecycleAware#onStart() and LifecycleAware#onStop() and unschedule your job onStop() method?

1 Like

No. Can you point to some samples of how and where it should be done? Thanks in advance.

How to use lifecycle:
How to use scheduler:
I think there(Step 5. Write the Component that Schedules the Task) you have everything you need to know how to set up your own Job.
Just simply add onStop() where you will be able to unschedule the Job :slight_smile:
Is this what are you looking for?

1 Like

Maybe. We currently extend JobRunner and inject SchedulerService, it also have scheduler.unscheduleJob. Thanks for information.