Advertisement
Guest User

Untitled

a guest
Nov 12th, 2013
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import os
  3. import time
  4. import threading
  5. from trytond.config import CONFIG
  6.  
  7. config_file = os.environ.get('TRYTOND_CONF', '/etc/trytond.conf')
  8. CONFIG.update_etc(config_file)
  9.  
  10. from trytond.backend import Database
  11. from trytond.pool import Pool
  12.  
  13. threads = {}
  14.  
  15.  
  16. def run_cron():
  17.     while True:
  18.         try:
  19.             db = Database().connect()
  20.             cursor = db.cursor()
  21.             db_list = db.list(cursor)
  22.             for db_name in db_list:
  23.                 thread = threads.get(db_name)
  24.                 if thread and thread.is_alive():
  25.                     continue
  26.                 pool = Pool(db_name)
  27.                 pool.init(update=False, lang=None)
  28.  
  29.                 Cron = pool.get('ir.cron')
  30.                 thread = threading.Thread(
  31.                         target=Cron.run,
  32.                         args=(db_name,), kwargs={})
  33.                 thread.start()
  34.                 threads[db_name] = thread
  35.         finally:
  36.             cursor.close(close=True)
  37.         time.sleep(60)
  38.  
  39.  
  40. if __name__ == '__main__':
  41.     run_cron()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement