<s> from django . core . management . base import BaseCommand , CommandError <EOL> from crons . models import Entry , Cronjob <EOL> from time import sleep , time <EOL> from travis_ping import travis_ping <EOL> from traceback import print_exc <EOL> def ping ( entry ) : <EOL> travis_token = entry . travis_token <EOL> repository = entry . gh_project <EOL> return travis_ping ( travis_token , repository ) <EOL> class Command ( BaseCommand ) : <EOL> help = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def handle ( self , * args , ** options ) : <EOL> started = time ( ) <EOL> frequency = None <EOL> if len ( args ) > <NUM_LIT:0> : <EOL> frequency = int ( args [ <NUM_LIT:0> ] ) <EOL> self . stdout . write ( '<STR_LIT>' ) <EOL> while True : <EOL> jobs = Cronjob . objects . all ( ) <EOL> for job in jobs : <EOL> if not job . need_run ( ) : continue <EOL> self . stdout . write ( '<STR_LIT>' + job . description + '<STR_LIT>' ) <EOL> for entry in job . entry_set . filter ( approved = True ) . exclude ( travis_token = '<STR_LIT>' ) : <EOL> self . stdout . write ( '<STR_LIT>' + entry . gh_project + '<STR_LIT:\n>' ) <EOL> try : ping ( entry ) <EOL> except : print_exc ( ) <EOL> job . run_now ( ) <EOL> job . save ( ) <EOL> self . stdout . write ( '<STR_LIT>' ) <EOL> ping ( Entry . objects . get ( gh_project = "<STR_LIT>" ) ) <EOL> before_next = min ( map ( lambda job : job . before_next_run ( ) , jobs ) ) <EOL> before_next = <NUM_LIT:0> if before_next < <NUM_LIT:0> else int ( before_next + <NUM_LIT:1> ) <EOL> if frequency and ( time ( ) + before_next ) > ( started + frequency ) : <EOL> self . stdout . write ( '<STR_LIT>' ) <EOL> break <EOL> self . stdout . write ( '<STR_LIT>' + str ( before_next ) + '<STR_LIT>' ) <EOL> self . stdout . flush ( ) <EOL> sleep ( before_next ) </s>
