示例#1
0
文件: feed.py 项目: daasara/riba
 def _init_sync(self):
     ''' create a sync event to store the info about this sync '''
     sync = SyncEvent()
     sync.started_at = datetime.now()
     sync.account = self.config['ACCOUNT']
     sync.save(using='default')
     return sync
示例#2
0
def get_ip(iface = 'eth0'):
    ifreq = struct.pack('16sH14s', iface, socket.AF_INET, '\x00'*14)
    try:
        res = fcntl.ioctl(sockfd, SIOCGIFADDR, ifreq)
    except:
        return None
    ip = struct.unpack('16sH2x4s8x', res)[2]
    return socket.inet_ntoa(ip)

if __name__ == '__main__':
    sync = SyncEvent()
    sync.account = 'Futurebazaar New Arrivals'
    sync.status = 'running'
    sync.started_at = datetime.now()
    sync.save()
    try:
        compute(sync)
        sync.status = 'finished'
    except Exception,e:
        sync.status = 'dead'
        import traceback
        import sys
        exc_info = sys.exc_info()
        st = '\n'.join(traceback.format_exception(*(exc_info or sys.exc_info())))
        sync.stack_trace = st
        sync.status = 'dead'
        try:
            ip_address = get_ip('eth0')
            subject = 'Futurebazaar New Arrivals Failed from IP - %s' % ip_address
            body = st
def get_ip(iface='eth0'):
    ifreq = struct.pack('16sH14s', iface, socket.AF_INET, '\x00' * 14)
    try:
        res = fcntl.ioctl(sockfd, SIOCGIFADDR, ifreq)
    except:
        return None
    ip = struct.unpack('16sH2x4s8x', res)[2]
    return socket.inet_ntoa(ip)


if __name__ == '__main__':
    sync = SyncEvent()
    sync.account = 'Tinla Compute Daily Order Count'
    sync.status = 'running'
    sync.started_at = datetime.now()
    sync.save()
    try:
        compute(sync)
        sync.status = 'finished'
    except Exception, e:
        sync.status = 'dead'
        import traceback
        import sys
        exc_info = sys.exc_info()
        st = '\n'.join(
            traceback.format_exception(*(exc_info or sys.exc_info())))
        sync.stack_trace = st
        sync.status = 'dead'
        try:
            ip_address = get_ip('eth0')
            subject = 'Tinla Compute Order Count Failed from IP - %s' % ip_address