On-schedule workflow stops when I'm trying to remove tag from issue

My small workflow is:
guard: (ctx) => {
  const issue = ctx.issue;
    return true;
},  
  action: (ctx) => {
    const issue = ctx.issue;
       if (issue.fields["Статус"] && issue.fields["Статус"].name !== "Подготовительный" && issue.fields["Статус"].name !== "Испытательный") {
       if(issue.tags && issue.tags){
         issue.tags.forEach((item) => {
         if (item && item.name === "Tag1") {
               issue.removeTag('Tag1');
               } 
           })   
        } 
  }  

But for some reason I got an error: 

Processing Issue 2-70688:
org.graalvm.polyglot.PolyglotException: Context execution was cancelled.

Maybe I'm doing something wrong?

0
8 comments
Hello,

I've just checked a similar on-change workflow on my environment, and it worked as expected. So generally, your rule should be fine, except for a too-wide guard condition. Usually, we recommend setting more specific conditions for the rule to fire to avoid performance problems.
However, you mentioned that your workflow rule is of an on-schedule type. Is that so? Could you please share the complete code? Are there any reasons to make it on-schedule instead of on-change?
The error you've received means the rule ran out of all provided resources, so I'm trying to understand what could be the reason for that.
I'm looking forward to your reply.
0

Hello,
I'm using on-schedule type rule because I have to change many issues. 
Full script:

exports.rule = entities.Issue.onSchedule({
  title: 'Cron-access-complete',
  search: '#Unresolved',
cron: '* * * * * ?',
  muteUpdateNotifications: true,
  guard: (ctx) => {
    const issue = ctx.issue;
    return true;
  },
action: (ctx) => {
    const issue = ctx.issue;
     if (issue.fields["Статус"] && issue.fields["Статус"].name !== "Подготовительный" && issue.fields["Статус"].name !== "Испытательный") {
         if(issue.tags && issue.tags){
issue.tags.forEach((item) => {
           if (item && item.name === "Доступы complete") {
                 issue.removeTag('Доступы complete');
                 console.log(issue.tags)
               } 
           })   
        } 
    }  
  },
  requirements: {
    // TODO: add requirements
  }
});

Thanks for notice about guard condition, I'll take it into account!

0

Thank you. Your rule now runs every second and processes all unresolved issues, which can load the server significantly and be the reason of the failure. Could you please describe your scenario?
If you want to process all existing issues just one time to remove the tag from certain issues, you can use an approach with an anchor issue specified in the search section (example). If you want to limit tagging an issue if it is set to particular states - it's better to handle it with an on-change rule that fires on tagging an issue and checks the conditions (example). I'll be happy to explain it in more details once I know more about your scenario.

0

Thank for reply and sorry for late response! My scenario is to fix all the issues in this project - remove tag if field "Status" is set to specific states. I tried to run my script every five minutes and I still get this error. 

0
Could you please tell me more about your installation? Is it Cloud or Server YouTrack? What version do you use?
Also, do you have any other custom workflows in this project? Please try disabling them to narrow the issue down. How many unresolved issues does your project have?
I'm looking forward to your reply.
0

Hello! We have server YouTrack, version 2022.3. Yes, we have some other custom workflows in this project, but I check and it seems like they don't affect this one. I'm not the owner of the tag, can it be the reason of it?

0

No, the ownership of the tag shouldn't cause this error. Usually, we see this error when the execution of the workflow rule took longer than we expect it to take. By default, there is a limit of time a rule can take to execute. 

On a side note, your use case can be solved without using a workflow. On the issue list page, you can search for issues that are not in those two states and that have the tag in question. After that, you can just select all these issues and apply a command that removes the tag. Namely, the following way should work:
1. Navigate to the issue list
2. Switch to the Classic interface (your avatar -> Appearance -> disable YouTrack Lite)

3. Enter the following query: `проект: <project name> Статус: -Испытательный, -Подготовительный тег: {Доступы complete}`. As a result, you will see all issues in that project that are not in these two states and have the tag.
4. Next, select all issues (there is a select all icon)

5. Type a command that removes a tag (`remove tag <tag name>` or, if you use Russian localization, `снять тег <tag name>`)

6. This action will remove the tag from all issues from the specified project that are not in the two specified states. Now, if you want to prevent tagging issues with this tag, you can create an on-change rule that will run when someone tags an issue. 

Will it work for you? 

If not, let's continue investigating the problem. I'd recommend temporarily disabling all other custom rules, updating the cron to fire once in at least 10 minutes, and updating the search expression to be more specific and return fewer issues. After that, try running the rule once again and, should you face the same error, share full YouTrack logs with me. For your convenience, you can upload them to our portal https://uploads.youtrack.cloud/ and let me know the name of the file when uploading is finished. Thank you.

0

Hello! I'm apologising for so late response and yes! this worked. Thank you very much!

0

Please sign in to leave a comment.