package start up service fails because dispatcher not started

i have a service which will frame a document and publishes to broker/local IS.
now this service is configured as a startup service for certain package.

the problem comes when i restart the server, upon package load, it executes the service, and then it executes the startup service. now since this service will publish docs, and by this time the dispatcher is not initialized, it fails with an exception.

is there a way where in i will start the service execution on package load only after i know that dispatcher is started…?

thank you

You should define package dependency for this package as being dependant on WmRoot. It will ensure that all WmRoot services are loaded before this package loads into the memory.

If what suggested by Ajaynaina not working (i guess it won’t since WmRoot is alway the first startup serivces to run and dispatcher start after all startup services are executed),
you can create another service which will register a one-time scheduled job for this service (use pub.scheduler:addOneTimeTask service), and scheduled it to run certain time (say 5 min) after the current system time.
hope this helps