Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Scheduled Tasks

We use following code to send pending reminders. This code is triggered at 5 minutes intervals. We use cluster locks (line 622) to ensure that only one instance of this task is running and if a new tasks is triggered before the previous task finished we simply skip new task.

We don't know whether the cluster locks are reentrant or not. So we also have an additional guard with an instance level "sendingReminders" flag (line 614).

Worst case scenario is sending a reminder will be delayed 5 more minutes. 

    if (this.sendingReminders) {
      log.warn("The add-on received a send pending reminders request while already processing reminders. You may be sending too many reminders, for example you may sending a reminder to large jira user group");
      return;
    }

    log.debug("Acquiring cluster lock for sending reminders");
    ClusterLock lock = clusterLockService.getLockForName(ReminderServiceImp.class.getName() + ".SendPendingReminders");
    boolean lockAcquired = lock.tryLock();
    if (!lockAcquired) {
      log.warn("Previous instance still running");
      return;
    }
    log.debug("Acquired cluster lock for sending reminders");
    try {
      sendPendingRemindersImp();
    } catch (Exception e) {
      log.error("Can't send pending reminders", e);
    } finally {
      this.sendingReminders = false;
      log.debug("Releasing cluster lock for sending reminders");
      lock.unlock();
    }

Transaction Management

We only retrieve active reminders (which are not triggered yet) when querying reminders to be sent. Although users may create more than one reminder for a single issue, most issues don’t require any reminder. In a normal usage, number of active reminders should be very small compared to the number of issues or users. We have also considered to use activeObjects.stream instead of following code segment but we need to modify Reminder object as not active and stream is returning read-only instances.

    Query query = Query.select().where("ACTIVE = ?", Boolean.TRUE);
    Reminder[] reminders = activeObjects.find(Reminder.class, query);


  • No labels