How to test on-schedule rule?

I try to make console.log() by schedule, but nothing is written: 

0
3 comments

Hi!

I'm Sergey from the YouTrack team.

Thank you for contacting us. I'm happy to help you.

This indicates that the workflow either doesn't work or doesn't match any issues specified in the project. I suggest that you follow these troubleshooting steps:

  • make sure that the search query returns issues in the UI search
  • make sure the workflow is attached to the project you test it in, active and produces no errors
  • change the cron expression to 'every minute': 0 * 0 ? * * *

Once you cover these steps, test it again, wait for a minute, and check if there's any output.

0

Hey, unfortunately this doesn't really help; no logging to the console is being done. What else am I supposed to use for search if I want to repeatedly create an issue?

/* eslint-disable */
var entities = require('@jetbrains/youtrack-scripting-api/entities');
var workflow = require('@jetbrains/youtrack-scripting-api/workflow');

exports.rule = entities.Issue.onSchedule({
  title: "Notification",
  cron: '0 * * * * ?',
  search: '',
  action: function(ctx) {
    const logger = new Logger(ctx.traceEnabled);
	console.log("hello")
  }
});

function Logger(useDebug = true) {
  return {
    log: (...args) => useDebug && console.log(...args),
    warn: (...args) => useDebug && console.warn(...args),
    error: (...args) => useDebug && console.error(...args)
  }
}
0

Hi!

console.log("hello") should appear when the rule runs if the workflow is attached to a project that has at least one issue. In JavaScript workflows, search: '' means all issues in the attached projects are processed.

Please check the essentials:

  • The workflow is attached to the project you are testing in. This means the project is selected in the workflow's Projects tab. See Attach a Workflow to a Project.
  • The project has at least one issue. The rule action runs once per issue matched by search.
  • You are checking the workflow editor console, not the browser console. See Troubleshooting Workflows.
  • You are checking after the next matching minute starts. 0 * * * * ? runs at second 0 of every minute.
  • There are no validation or runtime errors in the workflow editor console.

For creating exactly one issue on each schedule, use an anchor issue in search. Otherwise, the rule can create one new issue per matched issue.

exports.rule = entities.Issue.onSchedule({
  title: 'Notification',
  cron: '0 * * * * ?',
  search: 'issue id: DEMO-1',
  action: function(ctx) {
    console.log('hello');

    const newIssue = new entities.Issue(
      ctx.currentUser,
      ctx.issue.project,
      'Scheduled issue'
    );
  }
});

Here, DEMO-1 can be any existing issue in the project where the workflow is attached. You can find more details in the Issue.onSchedule API reference and the scheduled issue creation example.

0

Please sign in to leave a comment.