[ 
https://issues.apache.org/jira/browse/BEAM-8335?focusedWorklogId=361258&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-361258
 ]

ASF GitHub Bot logged work on BEAM-8335:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 18/Dec/19 01:51
            Start Date: 18/Dec/19 01:51
    Worklog Time Spent: 10m 
      Work Description: davidyan74 commented on pull request #10405: 
[BEAM-8335] Background caching job
URL: https://github.com/apache/beam/pull/10405#discussion_r359116365
 
 

 ##########
 File path: 
sdks/python/apache_beam/runners/interactive/background_caching_job.py
 ##########
 @@ -0,0 +1,101 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""Module to build and run background caching job.
+
+For internal use only; no backwards-compatibility guarantees.
+
+A background caching job is a job that caches events for all unbounded sources
+of a given pipeline. With Interactive Beam, one such job is started when a
+pipeline run happens (which produces a main job in contrast to the background
+caching job) and meets the following conditions:
+
+  #. The pipeline contains unbounded sources.
+  #. No such background job is running.
+  #. No such background job has completed successfully and the cached events 
are
+     still valid (invalidated when unbounded sources change in the pipeline).
+
+Once started, the background caching job runs asynchronously until it hits some
+cache size limit. Meanwhile, the main job and future main jobs from the 
pipeline
+will run using the deterministic replay-able cached events until they are
+invalidated.
+"""
+
+from __future__ import absolute_import
+
+import apache_beam as beam
+from apache_beam import runners
+from apache_beam.runners.interactive import interactive_environment as ie
+
+
+def attempt_to_run_background_caching_job(runner, user_pipeline, options=None):
+  """Attempts to run a background caching job for a user-defined pipeline.
+
+  If a background caching job is started, return the pipeline result. 
Otherwise,
+  return None.
+  The pipeline result is automatically tracked by Interactive Beam in case
+  future cancellation/cleanup is needed.
+  """
+  if is_background_caching_job_needed(user_pipeline):
+    # Cancel non-terminal jobs if there is any before starting a new one.
+    attempt_to_cancel_background_caching_job(user_pipeline)
+    # TODO(BEAM-8335): refactor background caching job logic from
+    # pipeline_instrument module to this module and aggregate tests.
+    from apache_beam.runners.interactive import pipeline_instrument as instr
+    runner_pipeline = beam.pipeline.Pipeline.from_runner_api(
+        user_pipeline.to_runner_api(use_fake_coders=True),
+        runner,
+        options)
+    background_caching_job_result = beam.pipeline.Pipeline.from_runner_api(
+        instr.pin(runner_pipeline).background_caching_pipeline_proto(),
+        runner,
+        options).run()
+    ie.current_env().set_pipeline_result(user_pipeline,
+                                         background_caching_job_result,
+                                         is_main_job=False)
+
+def is_background_caching_job_needed(user_pipeline):
+  """Determines if a background caching job needs to be started."""
+  background_caching_job_result = ie.current_env().pipeline_result(
+      user_pipeline, is_main_job=False)
+  from apache_beam.runners.interactive import pipeline_instrument as instr
+  # Checks if the pipeline contains unbounded sources.
+  return (instr.has_unbounded_sources(user_pipeline) and
 
 Review comment:
   This may not be in the scope of this PR, but we also need to let the user 
specify their own sources to be cached, because the user may have a large 
bounded source that they want to capture a small segment of.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 361258)
    Time Spent: 49h 20m  (was: 49h 10m)

> Add streaming support to Interactive Beam
> -----------------------------------------
>
>                 Key: BEAM-8335
>                 URL: https://issues.apache.org/jira/browse/BEAM-8335
>             Project: Beam
>          Issue Type: Improvement
>          Components: runner-py-interactive
>            Reporter: Sam Rohde
>            Assignee: Sam Rohde
>            Priority: Major
>          Time Spent: 49h 20m
>  Remaining Estimate: 0h
>
> This issue tracks the work items to introduce streaming support to the 
> Interactive Beam experience. This will allow users to:
>  * Write and run a streaming job in IPython
>  * Automatically cache records from unbounded sources
>  * Add a replay experience that replays all cached records to simulate the 
> original pipeline execution
>  * Add controls to play/pause/stop/step individual elements from the cached 
> records
>  * Add ability to inspect/visualize unbounded PCollections



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to