<s> import collections <EOL> from gearman . constants import PRIORITY_NONE , JOB_UNKNOWN , JOB_PENDING , JOB_CREATED , JOB_FAILED , JOB_COMPLETE <EOL> class GearmanJob ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , connection , handle , task , unique , data ) : <EOL> self . connection = connection <EOL> self . handle = handle <EOL> self . task = task <EOL> self . unique = unique <EOL> self . data = data <EOL> def to_dict ( self ) : <EOL> return dict ( task = self . task , job_handle = self . handle , unique = self . unique , data = self . data ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . connection , self . handle , self . task , self . unique , self . data ) <EOL> class GearmanJobRequest ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , gearman_job , initial_priority = PRIORITY_NONE , background = False , max_attempts = <NUM_LIT:1> ) : <EOL> self . gearman_job = gearman_job <EOL> self . priority = initial_priority <EOL> self . background = background <EOL> self . connection_attempts = <NUM_LIT:0> <EOL> self . max_connection_attempts = max_attempts <EOL> self . initialize_request ( ) <EOL> def initialize_request ( self ) : <EOL> self . result = None <EOL> self . exception = None <EOL> self . warning_updates = collections . deque ( ) <EOL> self . data_updates = collections . deque ( ) <EOL> self . status = { } <EOL> self . state = JOB_UNKNOWN <EOL> self . timed_out = False <EOL> def reset ( self ) : <EOL> self . initialize_request ( ) <EOL> self . connection = None <EOL> self . handle = None <EOL> @ property <EOL> def status_updates ( self ) : <EOL> """<STR_LIT>""" <EOL> output_queue = collections . deque ( ) <EOL> if self . status : <EOL> output_queue . append ( ( self . status . get ( '<STR_LIT>' , <NUM_LIT:0> ) , self . status . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) ) <EOL> return output_queue <EOL> @ property <EOL> def server_status ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . status <EOL> @ property <EOL> def job ( self ) : <EOL> return self . gearman_job <EOL> @ property <EOL> def complete ( self ) : <EOL> background_complete = bool ( self . background and self . state in ( JOB_CREATED ) ) <EOL> foreground_complete = bool ( not self . background and self . state in ( JOB_FAILED , JOB_COMPLETE ) ) <EOL> actually_complete = background_complete or foreground_complete <EOL> return actually_complete <EOL> def __repr__ ( self ) : <EOL> formatted_representation = '<STR_LIT>' <EOL> return formatted_representation % ( self . job . task , self . job . unique , self . priority , self . background , self . state , self . timed_out ) </s>
