'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'

@staticmethod
def parser_enable(id):

    db = current.db
    s3db = current.s3db
    table = s3db.msg_parser
    record = db((table.id == id)).select(table.id, table.enabled, table.channel_id, table.function_name, limitby=(0, 1)).first()
    if (not record.enabled):
        record.update_record(enabled=True)
    channel_id = record.channel_id
    function_name = record.function_name
    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, timeout=300, repeats=0)
        return 'Parser    enabled'
