Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Is there a way to check if an instance of a post-function is already running? Edited

I would like to prevent simultaneous execution of a particular post-function.

To put it simply:

  • User #1 presses a particular workflow button -> a post-function is executed.
  • While the post-function is still running user #2 presses the same workflow button -> Post-Function detects, that user #1 already executed the transition (to itself) and that the script is still running -> error message is returned.

Edit:

Extending the question: 
Would detecting this still be possible if I started a Thread inside the Post-Function, so that the main thread of the Post-Function finishes, while the Thread is still running in the background?

1 answer

1 accepted

0 votes
Answer accepted

You can't actually perform two post-functions at the same time.  Imagine the situation with two users looking at the same issue.

User 1 clicks "start progress", then user 2 hits the same a nanosecond later.  The transition process that the first one is performing has moved the issue into a state (even if it's a status looped back to itself) where the second call the transition might be invalid, so it won't actually do anything.  User 2 will get a message about the the state of the issue having being changed, so the transition they've requested is no longer valid.  As the first transition blocks any others, you can't get into a state where the same post-function is running twice

Obviously, that only applies for the one issue.  If your two users are looking at different issues, yes, the same post-function could run at the same time, but it will be running against two different issues, so they won't affect each other.

That makes a lot of sense. Thanks.

I assume if I chose to create a new thread from inside that post-function to do some task (so the user doesn't have to wait), then I wouldn't be able to prevent simultaneous executions of those threaded jobs, correct, unless maybe I have a "boolean" field "allow execution" on the context issue, set it to false in the main post-function, then set it to true again once the threaded task is finished?

Yes, that's the only way to do it, but you'll need to shift the logic a bit.  You can't do this detection stuff in the post function, you'll need to do it in the conditions on the transition, basically "don't allow the transition to start if the flagged-as-running field is set"

I also want to question what you're doing.  A post-function is only really suitable for processes that are single purpose, short and usually directly related to the issue being transitioned.

A long running process probably should be being run by something built to handle long running processes, and as you seem to want to prevent more than one of them running, we can be pretty sure it's not related to Jira.  It sounds like your transition should not be running the process itself, but passing a trigger to a build server so that can handle all the work properly.

That's good advice. Thanks.

I wrote a script to export data to Google Sheets in a very specific format, while also doing some calculations before sending the data. I also couldn't do it via scheduled job, since one requirement was for it to be executed on demand. It works well, but I just wanted to make sure, that there can only ever be a single export script running at the same time, as anything else would just be bogging down the instance with redundant JQL searches etc.

We have an extremely customized instance here, and I agree, that  passing a trigger to a build server would be best. It's a work-in-progress.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

How to log work and track time in Jira when a person is part of multiple teams

  The manager’s daily activities include a list of challenges to reach high levels of efficiency for their teams. Part of these challenges is related to how to deal with the worklog systems sin...

58 views 2 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you