Marc Lipoff
02/02/2023, 9:58 PMNate
02/02/2023, 10:06 PMMarc Lipoff
02/02/2023, 10:07 PM_config_environment_block = JSON(value=_config_environment)
_config_environment_block.save("config", overwrite=True)
and then I usually run prefect block register -f example.py
config
to config2
.... there exist 2 blocks... whereas I'd really want the first block deletedNate
02/02/2023, 10:15 PMprefect block register ...
command is meant to tell your orion server (cloud, or hosted) that the implementation of the Block
subclass has changed. So you'd only need to register
if you had done something like added an attribute to JSON
like
class JSON(Block):
# existing attrs
...
new_attr: str = "hi!"
the .save()
method is all you need to save new block instances
I'm not sure we'd want orion to inspect your code to see if blocks are being used, but it sounds like maybe a more flexible way to bulk-delete block instances would be useful?Marc Lipoff
02/02/2023, 10:17 PMprefect block register...
dryrun ?Nate
02/02/2023, 10:57 PMlist all the blocks defined in codedo you mean instances of a certain type of block (like
JSON
)?
e.g. _config_environment_block
Marc Lipoff
02/02/2023, 10:57 PMNate
02/02/2023, 10:58 PMblocks.py
from prefect.blocks.core import Block
class AddBlock(Block):
x: int = 1
y: int = 2
def add(self):
return self.x + self.y
class MultiplyBlock(Block):
x: int = 1
y: int = 2
def multiply(self):
return self.x * self.y
a = AddBlock(x=42)
m = MultiplyBlock(y=42)
import inspect
from prefect.blocks.core import Block
from prefect.utilities.importtools import load_script_as_module
filename = "blocks.py" # file where some block instances are defined
# load the file as a module
module = load_script_as_module(filename)
instances = [
obj for name, obj in inspect.getmembers(module)
if not inspect.isclass(obj) and isinstance(obj, Block)
]
print(instances) # yields [AddBlock(x=42, y=2), MultiplyBlock(x=1, y=42)]
i just threw this together but could be formalized if there was a desire to have some sort of dry run as a CLI cmd / utilMarc Lipoff
02/06/2023, 7:27 PM