Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
shaibarlev opened this issue Feb 28, 2024 · 14 comments
Open

Comments

@shaibarlev
Copy link

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
Copy link

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

@Siqsuruq
Copy link

Siqsuruq commented Mar 4, 2024

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
Copy link

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
Copy link

Siqsuruq commented Mar 4, 2024

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
Copy link
Author

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
Copy link

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
Copy link

Siqsuruq commented Mar 5, 2024

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
Copy link

Siqsuruq commented Mar 5, 2024

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
Copy link

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
Copy link

Siqsuruq commented Mar 5, 2024

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
Copy link

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
Copy link

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
Copy link
Author

Can you share ?

@TechyGuy99
Copy link

TechyGuy99 commented Mar 18, 2024

@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;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants