Post

5 followers Follow
0
Avatar

Question: How do I automatically restart a custom task that failed because of a server restart?

I have created a plugin that runs for a long time.
Basically, it creates an issue in an issue tracking system and then waits for the issue to be resolved.

I already made it so it is restartable (it doesn't create a new issue but recognizes the existing one), so it can survive server restarts.

However, the user needs to manually "retry" the task after a restart because it goes to failed status.  I've seen other tasks that remain "in progress" after a server restart.

How can I write the plugin so that it will also remain (or restart) after a server recycle?

Willem Monsuwe

Please sign in to leave a comment.

10 comments

0
Avatar

Hi Willem

Thanks for posting! Just to clarify: you're talking about restarting a task (in a release) that was running and that want to "FAILED" when the server restarts?

Also, could you give an indication of roughly how often this is happening, i.e. how often you are restarting the (production?) server - does this happen daily, or a few times a week, or..?

Regards

 

Andrew

Andrew Phillips 0 votes
0
Avatar

Yes, exactly!

It's not happening very often, one or two times a week perhaps, so it's not a pressing issue.

I was just wondering, because I saw some other (default) tasks that had not gone to "FAILED" status after a restart, but were still in progress.  So I was hoping this was possible for a custom (plugin) task as well.

Willem Monsuwe 0 votes
0
Avatar

Hi Willem,

What other tasks are you referring to? As far as I know, an automated task goes always into failed state when the server is restarted.

Of course you could automate the restarting part. When you start the XLR server, you can check if there're any failed task for your tasktype and automatically start them using the REST api.


Regards,
Joris

Joris De Winne 0 votes
0
Avatar

I think it was a manual task.
Are those handled differently by xlrelease internally?
Automatically restarting on a server startup seems like a good option.  Just need to find out where I can hook into the startup process, I'm sure that's documented somewhere.

Willem Monsuwe 0 votes
0
Avatar

Hi Willem,

In XLR 4.7, this will be using the internal api:

You can send an http post to

http://[XLR_URL]/tasks/[TASK_ID]/retry

Using the body

{"text":"ddd"}

 

Regards,
Joris

Joris De Winne 0 votes
0
Avatar

Hi Willem

> You can send an http post to
> http://[XLR_URL]/tasks/[TASK_ID]/retry
> Using the body
> {"text":"ddd"}

Just to add to this; here a link from the 4.0.x docs for this call:

https://docs.xebialabs.com/xl-release/4.0.x/rest-api/com.xebialabs.xlrelease.api.internal.TaskResource.html#/tasks/{taskId:%20[^/]+}/retry:POST

For the avoidance of doubt; as Joris said, this is the internal API, not the supported public API.

Regards


Andrew

Andrew Phillips 0 votes
0
Avatar

Update: I just noticed that one of the automated tasks that automatically restarts on server restart is the XLDeploy task (the one that starts a deployment task and then waits for it to complete).

So that's the behaviour I want to replicate.

Willem Monsuwe 0 votes
0
Avatar

Hi Willem

The XL Deploy task is not a regular plugin task. We plan to expose this reconnect-on-restart mechanism to custom tasks in the future.

Kind regards,

Hes Siemelink 0 votes