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.

Can I raise the Error event myself?
For instance, when certain criteria in the data are not met, I want the job to stop. It should raise the Error event, instead of a Completed event. Right?

You might try raising an exception. I don’t remember the particulars, but it seems that this would be a likely path.

1 Like

Yeah, that did the job for me. Thanks!