Example #1
0
def process(jobid):
    syslog.syslog(syslog.LOG_PID, 'Processing jobid {0}'.format(jobid))

    if not jobid:
        syslog.syslog(syslog.LOG_PID, 'got falsy jobid')
        return

    syslog.syslog(syslog.LOG_PID, 'Getting data for jobid {0}'.format(jobid))
    r = get_redis(db=3)
    data = r.hgetall('i:direct.pays:{0}'.format(jobid))

    if not data:
        syslog.syslog(syslog.LOG_PID, 'no data for jobid: {0}'.format(jobid))
        return

    syslog.syslog(syslog.LOG_PID, 'Got {0} bytes of data for jobid {1}'.format(len(repr(data)), jobid))

    dbcon = get_dbcon(data)

    if not dbcon:
        return

    cur = dbcon.cursor()

    sql = 'exec {0}.xsp_calculate_paylines @cycleid = ?, @payrunid = ?;'.format(('pays', 'ibu')['ibu' in data])
    params = (data.get('cycle'), data.get('pay_run'))
    syslog.syslog(syslog.LOG_PID, 'executing: {0}  [params: {1}]'.format(sql, params))

    try:
        cur.execute(sql, params)
    except Exception as e:
        syslog.syslog(syslog.LOG_PID, str(e))

    cur.close()
    dbcon.close()
Example #2
0
def calculate(request, cycle_id):
    #log = logging.getLogger('pays')

    cycle = Cycle.objects.get(pk=cycle_id)
    cycle.calc_date = datetime.datetime.now()
    cycle.save()

    try:
        current_pay_run = PayRun.objects.get(cycle=cycle_id, approved=True)
        current_pay_run.approved = False
        current_pay_run.save()
    except PayRun.DoesNotExist:
        pass

    pay_run = PayRun()
    pay_run.cycle = cycle
    pay_run.created_by = request.user.get('name')
    pay_run.approved_by = request.user.get('name')
    pay_run.approved_date = datetime.datetime.now()
    pay_run.save()

    r = get_redis(db=3)
    id = r.incr('ids:direct.pays')
    data = {'project': request.info.get('current_projectname'), 'cycle': cycle.id, 'pay_run': pay_run.id}
    r.hmset('i:direct.pays:{0}'.format(id), data)
    r.rpush('q:direct.pays', id)

#    mail.send_mail('Run Calculation:'+request.info.get('current_projectname')+' '+str(cycle_id)+':'+str(pay_run.id),
#                    'Run the thing',
#                    '*****@*****.**',
#                    ['*****@*****.**'],
#                    fail_silently=False)

    return HttpResponseRedirect(reverse('direct.pays.views.pays.calculating', args=[request.info.get('current_projectname'), cycle_id, pay_run.id]))
Example #3
0
def loop():
    syslog.openlog('direct.pays', syslog.LOG_PID)
    syslog.syslog(syslog.LOG_PID, 'Starting up: DEPLOY_MODE={0}'.format(DEPLOY_MODE))

    r = get_redis(db=3)
    syslog.syslog(syslog.LOG_PID, 'Acquired Redis connection: {0}'.format(r))

    syslog.syslog(syslog.LOG_PID, 'Entering main loop')

    try:
        while True:
            _, jobid = r.blpop('q:direct.pays')
            process(jobid)
    except KeyboardInterrupt:
        syslog.syslog(syslog.LOG_PID, 'Caught SIGINT; exiting')
        sys.exit(1)
Example #4
0
def loop():
    syslog.openlog('direct.pays', syslog.LOG_PID)
    syslog.syslog(syslog.LOG_PID,
                  'Starting up: DEPLOY_MODE={0}'.format(DEPLOY_MODE))

    r = get_redis(db=3)
    syslog.syslog(syslog.LOG_PID, 'Acquired Redis connection: {0}'.format(r))

    syslog.syslog(syslog.LOG_PID, 'Entering main loop')

    try:
        while True:
            _, jobid = r.blpop('q:direct.pays')
            process(jobid)
    except KeyboardInterrupt:
        syslog.syslog(syslog.LOG_PID, 'Caught SIGINT; exiting')
        sys.exit(1)
Example #5
0
def calculate(request, cycle_id):
    #log = logging.getLogger('pays')

    cycle = Cycle.objects.get(pk=cycle_id)
    cycle.calc_date = datetime.datetime.now()
    cycle.save()

    try:
        current_pay_run = PayRun.objects.get(cycle=cycle_id, approved=True)
        current_pay_run.approved = False
        current_pay_run.save()
    except PayRun.DoesNotExist:
        pass

    pay_run = PayRun()
    pay_run.cycle = cycle
    pay_run.created_by = request.user.get('name')
    pay_run.approved_by = request.user.get('name')
    pay_run.approved_date = datetime.datetime.now()
    pay_run.save()

    r = get_redis(db=3)
    id = r.incr('ids:direct.pays')
    data = {
        'project': request.info.get('current_projectname'),
        'cycle': cycle.id,
        'pay_run': pay_run.id
    }
    r.hmset('i:direct.pays:{0}'.format(id), data)
    r.rpush('q:direct.pays', id)

    #    mail.send_mail('Run Calculation:'+request.info.get('current_projectname')+' '+str(cycle_id)+':'+str(pay_run.id),
    #                    'Run the thing',
    #                    '*****@*****.**',
    #                    ['*****@*****.**'],
    #                    fail_silently=False)

    return HttpResponseRedirect(
        reverse('direct.pays.views.pays.calculating',
                args=[
                    request.info.get('current_projectname'), cycle_id,
                    pay_run.id
                ]))
Example #6
0
def process(jobid):
    syslog.syslog(syslog.LOG_PID, 'Processing jobid {0}'.format(jobid))

    if not jobid:
        syslog.syslog(syslog.LOG_PID, 'got falsy jobid')
        return

    syslog.syslog(syslog.LOG_PID, 'Getting data for jobid {0}'.format(jobid))
    r = get_redis(db=3)
    data = r.hgetall('i:direct.pays:{0}'.format(jobid))

    if not data:
        syslog.syslog(syslog.LOG_PID, 'no data for jobid: {0}'.format(jobid))
        return

    syslog.syslog(
        syslog.LOG_PID,
        'Got {0} bytes of data for jobid {1}'.format(len(repr(data)), jobid))

    dbcon = get_dbcon(data)

    if not dbcon:
        return

    cur = dbcon.cursor()

    sql = 'exec {0}.xsp_calculate_paylines @cycleid = ?, @payrunid = ?;'.format(
        ('pays', 'ibu')['ibu' in data])
    params = (data.get('cycle'), data.get('pay_run'))
    syslog.syslog(syslog.LOG_PID,
                  'executing: {0}  [params: {1}]'.format(sql, params))

    try:
        cur.execute(sql, params)
    except Exception as e:
        syslog.syslog(syslog.LOG_PID, str(e))

    cur.close()
    dbcon.close()