aelassas / wexflow

.NET Workflow Engine and Automation Platform
https://wexflow.github.io
MIT License
584 stars 162 forks source link

How to get results from one task as a parameters to next/other task. #69

Open shaibarlev opened 8 months ago

shaibarlev commented 8 months ago

I called a microservice with httpGet or httpPost , and I want to use the response from that task as a parameter to the next httpPost task. I would like to have a sample that demos it in the best practice way.

TechyGuy99 commented 8 months ago

same thing i am wondering about. I have ENVIRONMENT Task, have to pass its setting to HttpGet task. How does that work?

Siqsuruq commented 8 months ago

If you are using custom tasks you can programmatically pass data with Shared Memory or read files, here is link to docs how to read files in the next task: https://github.com/aelassas/wexflow/wiki/Custom-Tasks#files. Look at the comment that result is written to file: https://github.com/aelassas/wexflow/wiki/HttpGet.

TechyGuy99 commented 8 months ago

If you are using custom tasks you can programmatically pass data with Shared Memory or read files, here is link to docs how to read files in the next task: https://github.com/aelassas/wexflow/wiki/Custom-Tasks#files. Look at the comment that result is written to file: https://github.com/aelassas/wexflow/wiki/HttpGet.

Thanks for info. what i am not clear about is for any arbitrary activity, how do i know where to look for previous activity outputs and possibly inputs. Is there a contract where every activity has to store this in a well known place?

Siqsuruq commented 8 months ago

In your wexflow.xml configuration file there is a section where you can configure your temporary folder. When you run WF and some task creates an output, so output goes to this folder in the format wfId/date/time/task_timestamp. This way, next task in your wf knows where to read files,so the contents of the output files will automatically read and be available for your next task.

shaibarlev commented 8 months ago

On the same issue, the task only returns 4 statuses: Success, Warning, Error, Rejected. Tto get the http return codes like (200,202,304,400,404,500 and more) and the message return from any http verbs (Post, Get, Put, Delete) you'll need to read it from the files ?

P.S. on the page https://github.com/aelassas/wexflow/wiki/Tasks - the link to the HttpPost documentation doesn't show the sample/documentation for the task. it pointing to the main Wiki page.

TechyGuy99 commented 8 months ago

Ok, so i want to make a wf that based on a rest variable value, triggers a specific activity. is there a way to do that and example? Seems like i would need an actitivity that generates a switchvalue based on a rest input

Siqsuruq commented 8 months ago

I think most of the Wexflow project's standard tasks are more like an example, so you can write your own custom tasks. I've written an example of a simple custom task to get the response from the HTTP code and write it to a file. Here is a link GitHub The status of the task has nothing to do with the status of the HTTP response code, but you can create a custom task that will fail if the HTTP response, for example, is 400 or something like that.

Siqsuruq commented 8 months ago

For the another question I'm not quite understand what is "rest input". If you want to make a request and execute some specific task based on response, you can do it in one custom task, or create one which returns boolean or switch condition, if you want to use if/while switch. To do so just add boolean or switch condition to TaskStatus: return new TaskStatus(Status.Success , false);

TechyGuy99 commented 8 months ago

For the another question I'm not quite understand what is "rest input". If you want to make a request and execute some specific task based on response, you can do it in one custom task, or create one which returns boolean or switch condition, if you want to use if/while switch. To do so just add boolean or switch condition to TaskStatus: return new TaskStatus(Status.Success , false);

I wanted the input to the rest call to determine the switch output, so i could redirect the flow accordingly.

Siqsuruq commented 8 months ago

For the another question I'm not quite understand what is "rest input". If you want to make a request and execute some specific task based on response, you can do it in one custom task, or create one which returns boolean or switch condition, if you want to use if/while switch. To do so just add boolean or switch condition to TaskStatus: return new TaskStatus(Status.Success , false);

I wanted the input to the rest call to determine the switch output, so i could redirect the flow accordingly.

Input or output, still fuzzy for me. You want a custom task that accepts some parameters like make POST request to this URL and make a switch output. Smth like that?

TechyGuy99 commented 8 months ago

For the another question I'm not quite understand what is "rest input". If you want to make a request and execute some specific task based on response, you can do it in one custom task, or create one which returns boolean or switch condition, if you want to use if/while switch. To do so just add boolean or switch condition to TaskStatus: return new TaskStatus(Status.Success , false);

I wanted the input to the rest call to determine the switch output, so i could redirect the flow accordingly.

Input or output, still fuzzy for me. You want a custom task that accepts some parameters like make POST request to this URL and make a switch output. Smth like that? I am trying to set the CommentType on a comment. From that state, i want a rule that says for state A, set CommentState To some value, for TYpe B, CommentState = another value.

TechyGuy99 commented 8 months ago

I ended up writting a function that checks for rest, then local, then settings when a task runs.
Clean as i can set variables at workflow level or get some from the rest call.

shaibarlev commented 8 months ago

Can you share ?

TechyGuy99 commented 7 months ago

@shaibarlev public static string GetWorkflowVariableValue(this Wexflow.Core.Task task, string variableName, string defaultValue = null) {

  if (task == null)
      throw new ArgumentException("Null task");
  var workflow = task.Workflow;
  if (workflow == null) throw new ArgumentNullException("Null Workflow");

  var val = workflow.RestVariables.SingleOrDefault(r => r.Key == variableName)?.Value
      ?? workflow.LocalVariables.SingleOrDefault(v => v.Key == variableName)?.Value ??
      task.GetSetting(variableName, null) ?? workflow.GlobalVariables.SingleOrDefault(g => g.Key == variableName)?.Value
      ?? Environment.GetEnvironmentVariable(variableName);

  if (val == null && string.IsNullOrEmpty(val))
  {
      return defaultValue;
  }
  return val;

}