Code Monkey home page Code Monkey logo

Comments (7)

runabol avatar runabol commented on May 27, 2024

Did you check out each and map?

from piper.

anshumanr avatar anshumanr commented on May 27, 2024

Yes, each doesn't sound like a loop as it's done in parallel. map is as maps are. next type of functionality is what i need. Unless i am mistaken, none of the existing constructs seem to be able to do that.

from piper.

runabol avatar runabol commented on May 27, 2024

Maybe you can describe your use case.

from piper.

anshumanr avatar anshumanr commented on May 27, 2024

Use case is a usual programmatic flow.

Task 1 -> Task 2 (if condition then Task 5 else Task 3) -> Task 3 -> Task 4 -> End
            \-> Task 5 -> Task 6 -> Task 7 (if condition then Task 3 else Task 5)

Basically depending on conditions I may want to either jump ahead some tasks or go back to a previous task in the flow. switch allows me to do conditional branching but ability to alter flow by jumping to a task is missing.

From what i have understood so far, the DefaultTaskCompletionHandler handle() gets the next task to execute. A simple approach would be to use a next field to jump to a particular task based on task id.

Any thoughts on this approach?

from piper.

anshumanr avatar anshumanr commented on May 27, 2024

That's the change basically, and seems to work. Of course, next is working of internal task ids (starting with 0) and any change there would break this.

@@ -61,6 +61,7 @@ public class DefaultTaskCompletionHandler implements TaskCompletionHandler {
   @Override
   public void handle (TaskExecution aTask) {
     log.debug("Completing task {}, {}", aTask.getId(), jobRepository.toString());
+    int next = aTask.getInteger("next", -1);
     Job job = jobRepository.findJobByTaskId (aTask.getId());
     if(job!=null) {
       SimpleTaskExecution task = SimpleTaskExecution.createForUpdate(aTask);


@@ -74,7 +75,10 @@ public class DefaultTaskCompletionHandler implements TaskCompletionHandler {
         contextRepository.push(job.getId(), newContext);
       }
       if(hasMoreTasks(mjob)) {
-        mjob.setCurrentTask(mjob.getCurrentTask()+1);
+        if (next > 0)
+          mjob.setCurrentTask(next);
+        else
+          mjob.setCurrentTask(mjob.getCurrentTask()+1);
         jobRepository.merge(mjob);
         jobExecutor.execute(mjob);
       }

The sample script

label: My Pipeline

inputs:
  - name: name
    type: string
    required: true

tasks:      
  - label: Print a greeting
    type: print
    text: Hello ${name}
    next: 2

  - name: randomNumber
    label: Generate a random number
    type: randomInt
    startInclusive: 0
    endInclusive: 5000
    next: 4

  - name: randomNumber2
    label: Generate a random number
    type: randomInt
    startInclusive: 5000
    endInclusive: 15000

  - label: Print a farewell
    type: print
    text: Is this task skipped ${name}
    next: 1
       
  - label: Print a farewell
    type: print
    text: Goodbye ${name}

from piper.

runabol avatar runabol commented on May 27, 2024

That looks a lot like a goto. Not something I'd want to introduce. Seems like an if/else support would be more suitable for what you're trying to do.

from piper.

anshumanr avatar anshumanr commented on May 27, 2024

switch gives us if/else but doesn't give me the control I want. For now I will stick with my solution.

PS: just fyi, another flow control language is the Amazon state language, which does exactly the same with next

from piper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.