cancel
Showing results for 
Search instead for 
Did you mean: 

How to detect if system is still initializing

adiputera
Active Participant

Hi All,

How can we detect that the system is still initializing?

We have some after save listener that we don't want to be executed when the system is initialized.

I'm trying to use this, but it didn't work because it always return true

Registry.getCurrentTenantNoFallback().getJaloConnection().isSystemInitialized()

I'm trying to set session attribute in InitialDataSystemSetup and in the after save listener I would check if that attribute is null or not, and the result is always null.

So, how can we detect that the system is initializing?

adamreisberg
Active Participant

Hi adiputera

What are you trying to achieve with the After Save Listener?

You typically won't have the context of a session with an After Save Listener, as After Save Events are asynchronous (and I highly discourage changing the core.aftersave.async to true, as you would be modifying the CCV2 Commerce core configuration). Let us know the use case you are trying to solve for, and let's see if there exists a different path forward.

adiputera
Active Participant
0 Kudos

Hi adamreisberg

Basically in our after save listener, if some item type is modified, then it will modify other item type which have catalog, and then do catalog sync.

It's working fine, the only problem was when we do system initialization, the sync in that listener is stuck, even after we leave it overnight.

That's why I want to know how to detect if the initialization is yet to complete, so I can make sure that the logic inside listener will not be executed while initialization is yet to complete.

bizon1
Discoverer

Since there's some kind of locking already over there (you can't run 2 inits/updates at the same time), I would look into that direction.

adiputera
Active Participant
0 Kudos

@andrii1

That's a great idea, will look into that, although at the moment my approach of using property that is set from the backend works, checking the system locking seems a better approach.

Accepted Solutions (0)

Answers (2)

Answers (2)

adiputera
Active Participant

Okay, so I ended up using a property that I set in the backend (not in the local.properties)

In the InitialDataSystemSetup, at the beginning of the createProjectData method, I set the property by executing these code:

Config.setParameter(INIT_SYSTEM, "true");

Then in the AfterSaveListener, I just need to check if that parameter is null or not

if (null == Config.getParameter(INIT_SYSTEM))

If the parameter is null, it indicates that the system is not initializing. It's not perfect, but it does its job.

adamreisberg
Active Participant

Hi adiputera

Given that initialization only should happen once (1x) during the lifecycle of a SAP Commerce project, my recommendation is to add a configuration parameter that is changed when the application is initializing vs. when the application is running.

You would need to customize the custom After Save Event Listener to read the value of the property, and act on that

For setting the property, while initializing (or updating) in CCV2, you can configure through the hcs_admin (e.g. the presence or absence of said property).

If this solution does not work (and you need to use the After Save Event listener) observe the architecture of the Integration API module Webhook integration (which responds to After Save Events). This may give some additional direction on how you can design your solution.

adiputera
Active Participant
0 Kudos

Thanks adamreisberg-acn

In production, yes, it should happen only once

In local, initialization might needed when we mess up something while developing some feature.

I was thinking also about creating a property, but manual changing of the value is needed.