The Looping Pipeline in Syncraft serves as a looping mechanism akin to the programmatic "While" loops familiar to developers. This pipeline continually executes a specified logic until a defined break condition is met. It's an indispensable tool for scenarios necessitating repeated logic execution until certain conditions are satisfied, be it awaiting a status change in a database or processing large data chunks. Let's unravel the workings of the Looping Pipeline through a demonstrative example.
[
{
"query": {
"id": {
"eq": 2
}
},
"selection": {
"id": true,
"name": true
},
"root": "Users"
},
{
"while": {
"active": {
"eq": false
}
},
"do": {
"query": {
"id": {
"eq": 1
}
},
"selection": {
"id": true,
"name": true,
"active": true
},
"root": "Users"
},
"timebox": 5000
}
]
while
block houses the break condition. In this example, the loop will continue as long as the active
field is false.do
block contains the logic to be executed in each iteration. Here, it queries for a user with id
equal to 1 from the Users
root, selecting the id
, name
, and active
fields.timebox
parameter (expressed in milliseconds) is a safeguard to ensure the loop doesn't run indefinitely, terminating the loop if the specified duration is exceeded. Here, the loop will terminate if it runs longer than 5000 milliseconds (5 seconds), irrespective of the break condition.By encapsulating looping logic within the query pipeline, Synccraft ensures a structured, readable, and manageable way to handle iterative logic. This encapsulation also enhances data logic isolation from the caller, making the Looping Pipeline a powerful construct for handling iterative data processing tasks.