from service_utils import main, CmdService
import os
import sys
import redis
from subprocess import Popen

path=os.path.split(__file__)[0]

def start_q_server(stdout=None):
    exe_name=redis.__path__[0]+"/redis-server"
    if not os.name=='posix': exe_name+=".exe"
    return Popen(exe_name, stdout=stdout)

class QueueService(CmdService):
    _svc_name_ = "iClockQueueService"
    _svc_display_name_ = "iClock Queue Service"
    path = path
    cmd_and_args=redis.__path__[0]+"/redis-server.exe"
    def stop_fun(self, process):
        if not process: return
        q=redis.Redis(host='localhost', port=6379, db=0)
        q.save()
    
if __name__=='__main__':
    main(QueueService)
    