@staticmethod
    def parser_enable(id):
        """
            Enable a Parser
            - Connect a Parser to a Channel

            CLI API for shell scripts & to be called by S3Method

            @ToDo: Ensure only 1 Parser is connected to any Channel at a time
        """

        db = current.db
        s3db = current.s3db
        table = s3db.msg_parser
        record = db(table.id == id).select(table.id, # needed for update_record
                                           table.enabled,
                                           table.channel_id,
                                           table.function_name,
                                           limitby=(0, 1),
                                           ).first()
        if not record.enabled:
            # Flag it as enabled
            record.update_record(enabled = True)

        channel_id = record.channel_id
        function_name = record.function_name

        # Do we have an existing Task?
        ttable = db.scheduler_task
        args = '[%s, "%s"]' % (channel_id, function_name)
        query = ((ttable.function_name == "msg_parse") & \
                 (ttable.args == args) & \
                 (ttable.status.belongs(["RUNNING", "QUEUED", "ALLOCATED"])))
        exists = db(query).select(ttable.id,
                                  limitby=(0, 1)).first()
        if exists:
            return "Parser already enabled"
        else:
            current.s3task.schedule_task("msg_parse",
                                         args = [channel_id, function_name],
                                         period = 300,  # seconds
                                         timeout = 300, # seconds
                                         repeats = 0    # unlimited
                                         )
            return "Parser enabled"

    # -------------------------------------------------------------------------
dataset/ETHPy150Open sahana/eden/modules/s3db/msg.py/S3ParsingModel.parser_enable/original