@staticmethod
    def channel_enable(tablename, channel_id):
        """
            Enable a Channel
            - Schedule a Poll for new messages
            - Enable all associated Parsers

            CLI API for shell scripts & to be called by S3Method
        """

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

        # Enable all Parser tasks on this channel
        ptable = s3db.msg_parser
        query = (ptable.channel_id == channel_id) & \
                (ptable.deleted == False)
        parsers = db(query).select(ptable.id)
        for parser in parsers:
            s3db.msg_parser_enable(parser.id)

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

    # -------------------------------------------------------------------------
dataset/ETHPy150Open sahana/eden/modules/s3db/msg.py/S3ChannelModel.channel_enable/original