Пример #1
0
 def resume(self):
     """
     Attempt to resume any previous recipe that was started but
     not completed.
     """
     # Get the recipe that has been started most recently
     start_view = self.env_data_db.view(
         "openag/by_variable",
         startkey=[self.environment, "desired", RECIPE_START.name],
         endkey=[self.environment, "desired", RECIPE_START.name, {}],
         group_level=3)
     if len(start_view) == 0:
         return
     start_doc = start_view.rows[0].value
     # If a recipe has been ended more recently than the most recent time a
     # recipe was started, don't run the recipe
     end_view = self.env_data_db.view(
         "openag/by_variable",
         startkey=[self.environment, "desired", RECIPE_END.name],
         endkey=[self.environment, "desired", RECIPE_END.name, {}],
         group_level=3)
     if len(end_view):
         end_doc = end_view.rows[0].value
         if (end_doc["timestamp"] > start_doc["timestamp"]):
             return
     # Run the recipe
     self.start_recipe_service(
         StartRecipe._request_class(start_doc["value"]),
         start_doc["timestamp"])
Пример #2
0
    def __init__(self, server):
        self.env_data_db = server[ENVIRONMENTAL_DATA_POINT]
        self.recipe_db = server[RECIPE]

        # Indicates whether or not a recipe is running
        self.recipe_flag = Event()

        self.namespace = rospy.get_namespace()
        self.environment = self.namespace.split('/')[-2]

        rospy.init_node('recipe_handler')
        self.publishers = PublisherDict()
        rospy.Service(services.START_RECIPE, StartRecipe, self.start_recipe)
        rospy.Service(services.STOP_RECIPE, Empty, self.stop_recipe)
        rospy.set_param(params.SUPPORTED_RECIPE_FORMATS,
                        ','.join(self.recipe_class_map.keys()))

        self.current_recipe = None
        self.current_set_points = {}

        self.valid_variables = list(EnvVar.items.keys())

        rospy.set_param(params.CURRENT_RECIPE, "")
        rospy.set_param(params.CURRENT_RECIPE_START, 0)

        # Start publishing set points
        self.publish_set_points()

        # Get the recipe that has been started most recently
        start_view = self.env_data_db.view(
            "openag/by_variable",
            startkey=[self.environment, "desired", RECIPE_START.name],
            endkey=[self.environment, "desired", RECIPE_START.name, {}],
            group_level=3)
        if len(start_view) == 0:
            return
        start_doc = start_view.rows[0].value

        # If a recipe has been ended more recently than the most recent time a
        # recipe was started, don't run the recipe
        end_view = self.env_data_db.view(
            "openag/by_variable",
            startkey=[
                self.environment,
                "desired",
                RECIPE_END.name,
            ],
            endkey=[self.environment, "desired", RECIPE_END.name, {}],
            group_level=3)
        if len(end_view):
            end_doc = end_view.rows[0].value
            if (end_doc["timestamp"] > start_doc["timestamp"]):
                return

        # Run the recipe
        self.start_recipe(StartRecipe._request_class(start_doc["value"]),
                          start_doc["timestamp"])
Пример #3
0
    def __init__(self, server):
        self.env_data_db = server[DbName.ENVIRONMENTAL_DATA_POINT]
        self.recipe_db = server[DbName.RECIPE]

        # Indicates whether or not a recipe is running
        self.recipe_flag = Event()

        self.namespace = rospy.get_namespace()
        self.environment = self.namespace.split('/')[-2]

        rospy.init_node('recipe_handler')
        self.publishers = PublisherDict()
        rospy.Service(services.START_RECIPE, StartRecipe, self.start_recipe)
        rospy.Service(services.STOP_RECIPE, Empty, self.stop_recipe)
        rospy.set_param(
            params.SUPPORTED_RECIPE_FORMATS,
            ','.join(self.recipe_class_map.keys())
        )

        self.current_recipe = None
        self.current_set_points = {}

        rospy.set_param(params.CURRENT_RECIPE, "")
        rospy.set_param(params.CURRENT_RECIPE_START, 0)

        # Start publishing set points
        self.publish_set_points()

        # Get the recipe that has been started most recently
        start_view = self.env_data_db.view("openag/by_variable", startkey=[
            self.environment, EnvironmentalVariable.RECIPE_START, "desired"
        ], endkey=[
            self.environment, EnvironmentalVariable.RECIPE_START, "desired", {}
        ], group_level=3)
        if len(start_view) == 0:
            return
        start_doc = start_view.rows[0].value

        # If a recipe has been ended more recently than the most recent time a
        # recipe was started, don't run the recipe
        end_view = self.env_data_db.view("openag/by_variable", startkey=[
            self.environment, EnvironmentalVariable.RECIPE_END, "desired"
        ], endkey=[
            self.environment, EnvironmentalVariable.RECIPE_END, "desired", {}
        ], group_level=3)
        if len(end_view):
            end_doc = end_view.rows[0].value
            if (end_doc["timestamp"] > start_doc["timestamp"]):
                return

        # Run the recipe
        self.start_recipe(
            StartRecipe._request_class(start_doc["value"]),
            start_doc["timestamp"]
        )
Пример #4
0
 def recover_any_previous_recipe(self):
     """
     Attempt to resume any previous recipe that was started but
     not completed.
     """
     # Get the recipe that has been started most recently
     start_view = self.env_data_db.view(
         "openag/by_variable",
         startkey=[self.environment, "desired", RECIPE_START.name],
         endkey=[self.environment, "desired", RECIPE_START.name, {}],
         stale="update_after",
         group_level=3
     )
     if len(start_view) == 0:
         trace("recover_any_previous_recipe: No previous recipe to recover.")
         return
     start_doc = start_view.rows[0].value
     #trace("recover_any_previous_recipe: start_doc=%s", start_doc)
     # If a recipe has been ended more recently than the most recent time a
     # recipe was started, don't run the recipe
     end_view = self.env_data_db.view(
         "openag/by_variable",
         startkey=[self.environment, "desired", RECIPE_END.name],
         endkey=[self.environment, "desired", RECIPE_END.name, {}],
         stale="update_after",
         group_level=3
     )
     if len(end_view):
         end_doc = end_view.rows[0].value
         #trace("recover_any_previous_recipe: end_doc=%s", end_doc)
         if (end_doc["timestamp"] > start_doc["timestamp"]):
             trace("recover_any_previous_recipe: RETURNING: '\
                 'end_time=%s > start_time=%s",
                 end_doc["timestamp"], start_doc["timestamp"])
             return
     # Run the recipe
     trace("recover_any_previous_recipe: restarting recipe=%s at time=%s",
         start_doc["value"], start_doc["timestamp"])
     self.start_recipe_service(
         StartRecipe._request_class(start_doc["value"]),
         start_doc["timestamp"]
     )
 def recover_any_previous_recipe(self):
     """
     Attempt to resume any previous recipe that was started but
     not completed.
     """
     # Get the recipe that has been started most recently
     start_view = self.env_data_db.view(
         "openag/by_variable",
         startkey=[self.environment, "desired", RECIPE_START.name],
         endkey=[self.environment, "desired", RECIPE_START.name, {}],
         stale="update_after",
         group_level=3
     )
     if len(start_view) == 0:
         trace("recover_any_previous_recipe: No previous recipe to recover.")
         return
     start_doc = start_view.rows[0].value
     #trace("recover_any_previous_recipe: start_doc=%s", start_doc)
     # If a recipe has been ended more recently than the most recent time a
     # recipe was started, don't run the recipe
     end_view = self.env_data_db.view(
         "openag/by_variable",
         startkey=[self.environment, "desired", RECIPE_END.name],
         endkey=[self.environment, "desired", RECIPE_END.name, {}],
         stale="update_after",
         group_level=3
     )
     if len(end_view):
         end_doc = end_view.rows[0].value
         #trace("recover_any_previous_recipe: end_doc=%s", end_doc)
         if (end_doc["timestamp"] > start_doc["timestamp"]):
             trace("recover_any_previous_recipe: RETURNING: '\
                 'end_time=%s > start_time=%s",
                 end_doc["timestamp"], start_doc["timestamp"])
             return
     # Run the recipe
     trace("recover_any_previous_recipe: restarting recipe=%s at time=%s",
         start_doc["value"], start_doc["timestamp"])
     self.start_recipe_service(
         StartRecipe._request_class(start_doc["value"]),
         start_doc["timestamp"]
     )