Adam Saghy created FINERACT-2191:
------------------------------------

             Summary: ThreadLocal context handling during job execution
                 Key: FINERACT-2191
                 URL: https://issues.apache.org/jira/browse/FINERACT-2191
             Project: Apache Fineract
          Issue Type: Improvement
            Reporter: Adam Saghy
             Fix For: 1.12


We have different places where we are reinitializing the thread context when 
jobs are triggered, executed, started, but they should be reviewed and have a 
generic approach instead of setting them at different stages of the job trigger 
/ execution / starting.

*Acceptance criteria*
 * Places where we set context into ThreadLocal and reset to be reviewed and 
make sure we clean up after everything was executed

 ** ThreadLocalContextUtil.setTenant()

 ** ThreadLocalContextUtil.init()

 ** ThreadLocalContextUtil.reset()

 * 
org.apache.fineract.cob.service.AsyncLoanCOBExecutorServiceImpl#executeLoanCOBDayByDayUntilCOBBusinessDate->
 We can put the tenant identifier into the JobParameters field and pass it to 
the job starter

 * org.apache.fineract.infrastructure.jobs.service.JobStarter#run might be 
called by Quartz scheduler we need to make sure when we reach this point we 
either have an already initialized Thread context or we need to do it now:

 ** Jobparameters contains the tenant identifier with that we can fetch the 
tenant and update the ThreadContextUtil context

 *** tenant
 *** authentication
 *** business date
 * Whenever we init context, we should make sure it got reset once the job is 
done. We can use try - finally to achieve it, so it will be reset even an 
exception occurs!

 * org.apache.fineract.infrastructure.jobs.service.SchedulerJobListener
org.apache.fineract.infrastructure.jobs.service.SchedulerTriggerListener
org.apache.fineract.infrastructure.jobs.service.StuckJobListener
there are listener points where we either already set the context or we can… we 
should debug what is the order of execution for scheduled jobs (by quartz) or 
when we execution manually (run scheduled job), or inline COB.

 * org.apache.fineract.cob.loan.ContextAwareTaskDecorator Init and reset once 
done.

 * Places where ThreadLocalContextUtil.init is called

 ** 
org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierServiceImpl#beforeCommit

 ** 
org.apache.fineract.infrastructure.event.external.jobs.SendAsynchronousEventsTasklet#markEventsAsSent

 ** 
org.apache.fineract.portfolio.loanaccount.service.RecalculateInterestPoster#call

 ** org.apache.fineract.cob.loan.ContextAwareTaskDecorator#decorate

 ** 
org.apache.fineract.cob.service.AsyncLoanCOBExecutorServiceImpl#executeLoanCOBCatchUpAsync

 ** 
org.apache.fineract.infrastructure.bulkimport.service.BulkImportEventListener#onApplicationEvent

 ** 
org.apache.fineract.infrastructure.hooks.listener.FineractHookListener#onApplicationEvent

 ** 
org.apache.fineract.infrastructure.sms.scheduler.SmsMessageScheduledJobServiceImpl.SmsTask#run

 ** 
org.apache.fineract.infrastructure.springbatch.InputChannelInterceptor#beforeHandleMessage(org.apache.fineract.infrastructure.springbatch.ContextualMessage)

 ** 
org.apache.fineract.notification.eventandlistener.SpringNotificationEventListener#onApplicationEvent

 ** 
org.apache.fineract.portfolio.savings.jobs.postinterestforsavings.PostInterestForSavingTasklet#postInterest

 ** 
org.apache.fineract.portfolio.savings.service.SavingsSchedularInterestPosterTask#call



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to