-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathlocal.py
More file actions
60 lines (50 loc) · 1.9 KB
/
Copy pathlocal.py
File metadata and controls
60 lines (50 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
Bakery for baking pangeo-forge recipes in Direct Runner
"""
from apache_beam.pipeline import Pipeline, PipelineOptions
from traitlets import Integer
from .base import Bakery
from .execution_metadata import ExecutionMetadata
class LocalDirectBakery(Bakery):
"""
Bake recipes on your local machine, without docker.
Uses the Apache Beam DirectRunner
"""
num_workers = Integer(
0,
config=True,
help="""
Number of workers to use when baking the recipe.
Defaults to 0, which is interpreted by Apache beam to be the
number of CPUs on the machine
""",
)
def get_pipeline_options(
self, job_name: str, container_image: str, extra_options: dict
) -> PipelineOptions:
"""
Return PipelineOptions for use with this Bakery
"""
# Set flags explicitly to empty so Apache Beam doesn't try to parse the commandline
# for pipeline options - we have traitlets doing that for us.
return PipelineOptions(
flags=[],
runner="DirectRunner",
direct_running_mode="multi_processing",
direct_num_workers=self.num_workers,
save_main_session=True,
# this might solve serialization issues; cf. https://beam.apache.org/blog/beam-2.36.0/
pickle_library="cloudpickle",
**extra_options,
)
def bake(self, pipeline: Pipeline, meta: ExecutionMetadata) -> None:
"""
Executes the given pipeline using the provided for logs as appropriate.
pipeline (Pipeline): The pipeline object to be executed.
meta (ExecutionMetadata): An instance of BakeMetadata containing metadata about the bake process.
"""
self.log.info(
f"Running local job for recipe {meta.recipe_name}\n",
extra=meta.to_dict() | {"status": "running"},
)
pipeline.run()