'Run all the actions specified in the rule.
Args:
rule: Rule which actions are to be executed.
client_id: Id of a client where rule\'s actions are to be executed.
Returns:
Number of actions started.'

def _RunActions(self, rule, client_id):

    actions_count = 0
    for action in rule.actions:
        try:
            token = self.token.Copy()
            token.username = 'Foreman'
            if action.HasField('hunt_id'):
                if self._CheckIfHuntTaskWasAssigned(client_id, action.hunt_id):
                    logging.info('Foreman:    ignoring    hunt    %s    on    client    %s:    was    started    here    before', client_id, action.hunt_id)
                else:
                    logging.info('Foreman:    Starting    hunt    %s    on    client    %s.', action.hunt_id, client_id)
                    flow_cls = flow.GRRFlow.classes[action.hunt_name]
                    flow_cls.StartClients(action.hunt_id, [client_id])
                    actions_count += 1
            else:
                flow.GRRFlow.StartFlow(client_id=client_id, flow_name=action.flow_name, token=token, **action.argv.ToDict())
                actions_count += 1
        except Exception as e:
            logging.exception('Failure    running    foreman    action    on    client    %s:    %s', action.hunt_id, e)
    return actions_count
