Sung Kim
07/09/2023, 6:42 AMMarvin
07/09/2023, 6:42 AMpython
from prefect import task
from prefect.blocks.system import Secret
@task
def save_secret(name, value):
Secret(value=value).save(name=name, overwrite=True)
@task
def load_secret(name):
return Secret.load(name)
@flow
def save_and_load_secret():
save_secret("my-super-secret", "super secret contents")
secret: Secret = load_secret("my-super-secret")
assert secret.get() == "super secret contents", secret
if __name__ == "__main__":
save_and_load_secret()
This script defines two tasks: save_secret
and load_secret
. The save_secret
task creates a new Secret block with a given name and value, and the load_secret
task loads a Secret block by its name. The save_and_load_secret
flow demonstrates how to use these tasks to save a secret and then load it.
You can find more details in the Prefect documentation and the source code on GitHub.
Remember, with great power comes great responsibility. Use your secrets wisely, or else they might not be secrets for long.Sung Kim
07/11/2023, 4:48 AMMarvin
07/11/2023, 4:48 AMmongodb_host
, mongodb_port
, mongodb_db
, mongodb_collection
, and rest_url
.
When you run your flow, you need to provide these parameters. Here's an example of how you might do this:
python
flow.run(
parameters={
"mongodb_host": "your_mongodb_host",
"mongodb_port": "your_mongodb_port",
"mongodb_db": "your_mongodb_db",
"mongodb_collection": "your_mongodb_collection",
"rest_url": "your_rest_url",
}
)
Replace "your_mongodb_host"
, "your_mongodb_port"
, "your_mongodb_db"
, "your_mongodb_collection"
, and "your_rest_url"
with your actual values.
Remember, the parameters you pass to flow.run()
must match the parameters your flow expects. If you're still having trouble, you might want to double-check your flow definition to make sure you've defined all the parameters correctly.
And remember, humans, always keep track of your parameters. It's not like they're going to remember themselves.Sung Kim
07/11/2023, 6:05 AMMarvin
07/11/2023, 6:06 AMrun
method on a function object, which doesn't have such an attribute.
In Prefect, the run
method is typically called on a Flow
object, not a function. Here's an example of how you might define and run a flow:
python
from prefect import Flow, Parameter
# Define your flow
with Flow("My Flow") as flow:
x = Parameter("x")
# Run your flow
flow.run(parameters={"x": 42})
In this example, flow
is an instance of the Flow
class, which does have a run
method.
If you're still seeing this error, it might be because you're trying to call run
on a function that's meant to be a task within your flow. In that case, you'll need to include that function in your flow definition and then call run
on the flow itself.
Remember, it's all fun and games until someone loses an attribute.