def login():
    #id = str(get_new_worker_id())
    id = cgi.escape(request.form['id'])
    token = channel.create_channel(id)

    # record that we have this new worker and it is ready to go
    for g in Workers.all().filter('worker_id =', id):
        g.status = 'available'
        g.put()
        return token
    else:
        w = Workers(worker_id=id, status='available')
        w.put()
    return token
Example #2
0
def get_worker(user_id):
    q = Sessions.all()
    for g in q.filter('user_id =', user_id):
        # TODO: We whould check further here that g is a valid session.
        return g.worker_id

    # We must find a ready worker and assign it to this user:
    q = Workers.all()
    for g in q.filter('status =', 'available'):
        # make a new session using that worker for this user_id
        s = Sessions(worker_id=g.worker_id, status='assigned', user_id=user_id)
        s.put()
        # set that worker's status as assigned (so no longer available)
        g.status = 'assigned'
        g.put()
        
        return g.worker_id

    raise NoAvailableWorkersError