I'm using https://sematic.dev, and I have a couple of Sematic functions that I want to execute in a particular order, let's call them foo and bar:
@sematic.func
def foo(x: int) -> int:
print(f"Hi foo, {x}!")
return x * 2
@sematic.func
def bar(x: int) -> int:
print(f"Hi bar, {x}!")
return x * 3
@sematic.func
def pipeline() -> typing.List[int]:
return [foo(1), bar(1)]
print(pipeline().resolve())
But when I run this in the cloud, sometimes bar runs first and I always want foo to run first. How can I do that?
In general, if you're asking this question, it usually means that there's actually a data dependency between the thing you want to run first and the thing you want to run second. In your case, there is probably some data from
foothatbaris using. This data may be in some external system like a database, which might be why you're not already representing it in your Sematic functions as inputs and outputs. The best solution is to make this data dependency explicit, havingfooreturn a reference to the data used bybarand passing that reference in explicitly.However, if for some reason it's very difficult to do this, you can always create a dependency between two functions by feeding the output of one function to the input of another (and then just ignoring it in the second function). In your case that would look something like this: