def main(): db = agn.DBaseID() if db is None: agn.die(s='Failed to setup database') c = db.cursor() if c is None: agn.die(s='Failed to connect to database') active = 0 companies = {} query = ( 'SELECT status_id, mailing_id, genstatus, genchange, status_field ' 'FROM maildrop_status_tbl ' 'WHERE genchange > :limit AND (genstatus = 2 OR (genstatus = 1 AND status_field IN (\'A\', \'T\', \'W\')))' ) now = datetime.datetime.now() limit = now.fromordinal(now.toordinal() - 1) for (statusID, mailingID, genstatus, genchange, statusField) in c.queryc(query, {'limit': limit}): if isActive(genstatus, genchange, statusField): active += 1 rc = c.querys( 'SELECT company_id, shortname FROM mailing_tbl WHERE mailing_id = :mid', {'mid': mailingID}) if not rc is None and not None in rc: (companyID, mailingName) = rc try: company = companies[companyID] except KeyError: rc = c.querys( 'SELECT shortname FROM company_tbl WHERE company_id = :cid', {'cid': companyID}) if not rc is None and not rc[0] is None: company = rc[0] else: company = '#%d' % companyID companies[companyID] = company if genstatus == 1: status = 'is starting up to generate' else: status = 'is in generation' rc = c.querys( 'SELECT current_mails, total_mails FROM mailing_backend_log_tbl WHERE status_id = :sid', {'sid': statusID}) if (rc is None or None in rc) and statusField == 'W': rc = c.querys( 'SELECT current_mails, total_mails FROM world_mailing_backend_log_tbl WHERE mailing_id = :mid', {'mid': mailingID}) if not rc is None and not None in rc: status += ' (%d of %d are created)' % (rc[0], rc[1]) else: status += ' (nothing created until now)' print 'Mailing %s (%d) for Company %s (%d) %s' % ( mailingName, mailingID, company, companyID, status) c.close() db.close() if active > 0: print '%d jobs still active' % active sys.exit(1) sys.exit(0)
def main (pgm, args): opts = getopt.getopt (args, '') parm = opts[1] if len (parm) == 0: agn.die (s = 'Usage: %s <command> [<command-parameter>]' % pgm) ctrl = SMCtrl () if not ctrl.valid: agn.die (s = 'Failed to setup database interface') fail = None if parm[0] == 'status': if ctrl.enabled (): print '1' else: print '0' elif parm[0] == 'enable': ctrl.enable () elif parm[0] == 'disable': ctrl.disable () else: fail = 'Unknown command %s' % parm[0] ctrl.done () if not fail is None: agn.die (s = fail)
#!/usr/bin/env python import agn import re import os agn.require('2.3.0') agn.loglevel = agn.LV_INFO agn.lock() agn.log(agn.LV_INFO, 'main', 'Starting up') db = agn.DBaseID() if db is None: agn.die(s='Failed to setup database interface') db.log = lambda a: agn.log(agn.LV_DEBUG, 'db', a) curs = db.cursor() if curs is None: agn.die(s='Failed to get database cursor') emails = set() for record in curs.query("select param from mailing_mt_tbl"): m = re.search('from=".*<(.*)>', record[0]) if not m.group(1) is None: emails.add(m.group(1)) mailloop = "select concat('ext_', b.rid, '@', a.mailloop_domain) from ' + 'company_tbl a inner join " mailloop += "mailloop_tbl b on a.company_id = b.company_id where ' + 'forward_enable = 0 and "
use.append(u) updates = [] for u in use: if u == 'bounce': nu = UpdateBounce() elif u == 'account': nu = UpdateAccount() else: nu = None agn.log(agn.LV_ERROR, 'main', 'Invalid update: %s' % u) if not nu is None: if updparm.has_key(u): nu.options(updparm[u]) updates.append(nu) if len(updates) == 0: agn.die(agn.LV_ERROR, 'main', 'No update procedure found') agn.lock() agn.log(agn.LV_INFO, 'main', 'Starting up') while not term: agn.mark(agn.LV_INFO, 'loop', 180) db = None for upd in updates: if not term and upd.shouldRun() and upd.exists(): if db is None: db = agn.DBase() if db is None: agn.log(agn.LV_ERROR, 'loop', 'Unable to connect to database') if not db is None: instance = db.cursor() if not instance is None:
def main (): global term signal.signal (signal.SIGINT, handler) signal.signal (signal.SIGTERM, handler) if not agn.iswin: signal.signal (signal.SIGHUP, signal.SIG_IGN) signal.signal (signal.SIGPIPE, signal.SIG_IGN) # opts = getopt.getopt (sys.argv[1:], 'vso:') verbose = False single = False updparm = {} use = [] for opt in opts[0]: if opt[0] == '-v': agn.outlevel = agn.LV_DEBUG agn.outstream = sys.stdout verbose = True elif opt[0] == '-s': single = True elif opt[0] == '-o': parm = opt[1].split (':', 1) if len (parm) == 2: v = parm[1].split ('=', 1) if len (v) == 1: v.append ('true') if updparm.has_key (parm[0]): updparm[parm[0]].append (v) else: updparm[parm[0]] = [v] if not parm[0] in use: use.append (parm[0]) for u in opts[1]: if not u in use: use.append (u) updates = [] for u in use: if u == 'bounce': nu = UpdateBounce () elif u == 'account': nu = UpdateAccount () else: nu = None agn.log (agn.LV_ERROR, 'main', 'Invalid update: %s' % u) if not nu is None: if updparm.has_key (u): nu.options (updparm[u]) updates.append (nu) if len (updates) == 0: agn.die (agn.LV_ERROR, 'main', 'No update procedure found') agn.lock () agn.log (agn.LV_INFO, 'main', 'Starting up') if True: while not term: db = None agn.mark(agn.LV_INFO, 'loop', 180) for upd in updates: if not term and upd.shouldRun() and upd.exists(): if db is None: db = agn.DBaseID() if db is None: agn.log(agn.LV_ERROR, 'loop', 'Unable to connect to database') if db: if verbose: db.log = lambda a: sys.stdout.write('%s\n' % a) instance = db.cursor() if instance: if not upd.update(instance): agn.log(agn.LV_ERROR, 'loop', 'Update for %s failed' % upd.name) instance.close() else: agn.log(agn.LV_ERROR, 'loop', 'Unable to get database cursor') if db: db.close() if single: term = True # # Zzzzz.... countDelay = delay while countDelay > 0 and not term: if agn.iswin and agn.winstop (): term = True break time.sleep(1) countDelay -= 1 for upd in updates: upd.done() agn.log (agn.LV_INFO, 'main', 'Going down') agn.unlock ()
* Reserved. * * Contributor(s): AGNITAS AG. ********************************************************************************** """ # import time import agn agn.require ('2.3.0') agn.loglevel = agn.LV_INFO # agn.lock () agn.log (agn.LV_INFO, 'main', 'Starting up') db = agn.DBaseID () if db is None: agn.die (s = 'Failed to setup database interface') db.log = lambda a: agn.log (agn.LV_DEBUG, 'db', a) curs = db.cursor () if curs is None: agn.die (s = 'Failed to get database cursor') mailtrackTable = 'bounce_collect_tbl' # # # 1.) Kill old softbounces old = time.localtime (time.time () - 179 * 24 * 60 * 60) query = 'DELETE FROM softbounce_email_tbl WHERE creation_date < \'%04d-%02d-%02d\'' % (old[0], old[1], old[2]) try: agn.log (agn.LV_INFO, 'kill', 'Remove old addresses from softbounce_email_tbl') rows = curs.update (query, commit = True) agn.log (agn.LV_INFO, 'kill', 'Removed %d address(es)' % rows)
use.append (u) updates = [] for u in use: if u == 'bounce': nu = UpdateBounce () elif u == 'account': nu = UpdateAccount () else: nu = None agn.log (agn.LV_ERROR, 'main', 'Invalid update: %s' % u) if not nu is None: if updparm.has_key (u): nu.options (updparm[u]) updates.append (nu) if len (updates) == 0: agn.die (agn.LV_ERROR, 'main', 'No update procedure found') agn.lock () agn.log (agn.LV_INFO, 'main', 'Starting up') while not term: agn.mark (agn.LV_INFO, 'loop', 180) db = None for upd in updates: if not term and upd.shouldRun () and upd.exists (): if db is None: db = agn.DBase () if db is None: agn.log (agn.LV_ERROR, 'loop', 'Unable to connect to database') if not db is None: instance = db.cursor () if not instance is None: if not upd.update (instance):
def main(): global term signal.signal(signal.SIGINT, handler) signal.signal(signal.SIGTERM, handler) if not agn.iswin: signal.signal(signal.SIGHUP, signal.SIG_IGN) signal.signal(signal.SIGPIPE, signal.SIG_IGN) # opts = getopt.getopt(sys.argv[1:], 'vso:') verbose = False single = False updparm = {} use = [] for opt in opts[0]: if opt[0] == '-v': agn.outlevel = agn.LV_DEBUG agn.outstream = sys.stdout verbose = True elif opt[0] == '-s': single = True elif opt[0] == '-o': parm = opt[1].split(':', 1) if len(parm) == 2: v = parm[1].split('=', 1) if len(v) == 1: v.append('true') if updparm.has_key(parm[0]): updparm[parm[0]].append(v) else: updparm[parm[0]] = [v] if not parm[0] in use: use.append(parm[0]) for u in opts[1]: if not u in use: use.append(u) updates = [] for u in use: if u == 'bounce': nu = UpdateBounce() elif u == 'account': nu = UpdateAccount() else: nu = None agn.log(agn.LV_ERROR, 'main', 'Invalid update: %s' % u) if not nu is None: if updparm.has_key(u): nu.options(updparm[u]) updates.append(nu) if len(updates) == 0: agn.die(agn.LV_ERROR, 'main', 'No update procedure found') agn.lock() agn.log(agn.LV_INFO, 'main', 'Starting up') if True: while not term: db = None agn.mark(agn.LV_INFO, 'loop', 180) for upd in updates: if not term and upd.shouldRun() and upd.exists(): if db is None: db = agn.DBaseID() if db is None: agn.log(agn.LV_ERROR, 'loop', 'Unable to connect to database') if db: if verbose: db.log = lambda a: sys.stdout.write('%s\n' % a) instance = db.cursor() if instance: if not upd.update(instance): agn.log(agn.LV_ERROR, 'loop', 'Update for %s failed' % upd.name) instance.close() else: agn.log(agn.LV_ERROR, 'loop', 'Unable to get database cursor') if db: db.close() if single: term = True # # Zzzzz.... countDelay = delay while countDelay > 0 and not term: if agn.iswin and agn.winstop(): term = True break time.sleep(1) countDelay -= 1 for upd in updates: upd.done() agn.log(agn.LV_INFO, 'main', 'Going down') agn.unlock()