<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _AddForemanRule(self):
 """Adds a foreman rule for this hunt."""

    if data_store.RelationalDBEnabled():
      # Relational DB uses ForemanCondition objects.
      foreman_condition = foreman_rules.ForemanCondition(
          creation_time=rdfvalue.RDFDatetime.Now(),
          expiration_time=self.context.init_start_time + self.context.duration,
          description="Hunt %s %s" %
          (self.session_id, self.runner_args.hunt_name),
          client_rule_set=self.runner_args.client_rule_set,
          hunt_id=self.session_id.Basename(),
          hunt_name=self.runner_args.hunt_name)

      # Make sure the rule makes sense.
      foreman_condition.Validate()

      data_store.REL_DB.WriteForemanRule(foreman_condition)
    else:
      foreman_rule = foreman_rules.ForemanRule(
          created=rdfvalue.RDFDatetime.Now(),
          # TODO: Hunt context should differentiate between initial
          # and last start time (similarly to normal hunt objects).
          expires=self.context.create_time + self.context.duration,
          description="Hunt %s %s" %
          (self.session_id, self.runner_args.hunt_name),
          client_rule_set=self.runner_args.client_rule_set)

      foreman_rule.actions.Append(
          hunt_id=self.session_id,
          hunt_name=self.runner_args.hunt_name,
          client_limit=self.runner_args.client_limit)

      # Make sure the rule makes sense.
      foreman_rule.Validate()

      with aff4.FACTORY.Open(
          "aff4:/foreman",
          mode="rw",
          token=self.token,
          aff4_type=aff4_grr.GRRForeman) as foreman:
        rules = foreman.Get(
            foreman.Schema.RULES, default=foreman.Schema.RULES())
        rules.Append(foreman_rule)
        foreman.Set(rules)