__main__.py 892 B

123456789101112131415161718192021222324252627282930313233343536
  1. """Main application"""
  2. import time
  3. import sys
  4. from app import SCHEDULER, LOGGER, RESOURCE_NAMES, job_storage, jobs
  5. if __name__ == '__main__':
  6. # jobs.check_resources(RESOURCE_NAMES['gold'])
  7. # jobs.refill_resource(RESOURCE_NAMES['gold'])
  8. # sys.exit(0)
  9. JOBS = job_storage.get_jobs()
  10. for job in JOBS:
  11. LOGGER.info(
  12. 'Track resource "%s" at "%s"',
  13. job['resource_type'],
  14. job['minutes'],
  15. )
  16. SCHEDULER.add_job(
  17. jobs.check_resources,
  18. 'cron',
  19. args=[RESOURCE_NAMES[job['resource_type']]],
  20. id=job['resource_type'],
  21. replace_existing=True,
  22. minute=job['minutes']
  23. )
  24. try:
  25. while True:
  26. time.sleep(100)
  27. except KeyboardInterrupt:
  28. LOGGER.info('Exiting application')
  29. SCHEDULER.shutdown()
  30. sys.exit(0)