Worker Error

Hi, I understand from the Xojo documentation that if a Worker raises an error, the Error method is run. What happens then? Does that instance of the worker console app stop or does it continue to run? If it stops, does it stop gracefully and will the worker class restart it? In the word count example, the code uses the Start method to restart the worker if an error occurs to process the request again. Is that best practice? It seems to me that could cause an error loop. Can anyone comment on this?

Currently the event Error is

Worker.Error(jobData As String)

And would be better something like Worker.Error(errorCode As Int32, errorDetail As String)

Then Xojo could list some error codes and devs could handle then better and avoid traps as you said.

What’s the code for the Worker is dead?
What’s the code for the worker is alive but not responding?
What other situations exists and their codes?

Workers MUST be codependent in a master/slave interaction, so when the master dies, the worker should detect such loss and die later logging the unexpected termination. If the worker dies, the master should get (detect and raise) an error event reporting this situation. The Xojo behavior needs more documentation.

1 Like

A Worker Helper (Console App) quits when there is an error condition. The Worker does not restart the Helper, but you can do so by calling Start(). Since the Error event provides you with the jobData that was running when the error occurred, you can track if it is repeatedly failing and take the action that is appropriate for your app.

Thanks Paul. If you call Start() and there are already Worker Helpers running, will there be any effect on them? Will they be stopped and restarted, or is it only the stopped Worker Helpers that will be restarted?

Only stopped workers are restarted. Running workers are not affected.