Query worker "business"

Hi,
We’re trying to script some code to determine if a worker is busy (executing a task) or not.
I can’t seem to find anything in the tasks api that lets me determine this, and the “node” attribute points to the octopus server, not worker.

So I guess my question is: Is there a way to determine if a worker is busy using the rest api?

Hi @trond

The short answer is, unfortunately; no, there’s not currently any easy way to determine if a worker is busy using the REST API.

You’ve not mentioned if you’re running Octopus Cloud or Octopus Server, but if it’s the latter, then there might be one way to see. I’ll be completely transparent - I don’t even like suggesting it but I like customers to have all the facts :slight_smile:

In the Octopus database, we have a table called [dbo].[WorkerTaskLease]. I’m not 100% sure if a row is kept in there for the duration of a deployment, or just when it’s in use by a task. This table doesn’t have any corresponding REST API endpoint, meaning if you wanted to get access to this data, you’d need to access the database directly. This is one of the reason’s I don’t like suggesting it, since you lose the RBAC controls built into Octopus Server (and API).

We do have a couple of example scripts of using the REST API to get details about workers:

I don’t think either matches exactly what you’re looking to find out, but I thought they might be useful in case you wanted to explore writing something to determine if a worker is busy. It’d involve querying all running tasks, and searching the task logs as both examples above do.

I’m sorry I don’t have any better suggestions for you, I’d like to see Workers have more first-class API support myself so that it’s easier to query for things such as this.

I hope that helps!

Hi @mark.harrison , I appreciate the honesty. I remember the workertasklease table, there was a bug related to some locks in that table a few years ago :-).

Your second scripts shows using the verbose=true with the rest api, and it seems like it’s possible to grab data from the verbose data returned by line-parsing and looking for “Leased worker*”.
It’s definetely not as clean as I think it should be, but we can work with this I think. Thank you!

btw if there isn’t already a feature request for a richer rest api related to worker status I wouldn’t mind if one was created.

again, thanks a lot for your response, appreciate it!

  • Trond

Hi @trond

You’re very welcome. From what I could tell on our feature request website (https://octopusdeploy.uservoice.com/) the specific request for better REST API Support for Workers isn’t there.

I’d recommend adding it there in the first instance, and I’ll see if there are any future plans internally on this.

Best regards

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.