def setupUniqueUserIdAdder(job_entity): """Job that setup jobs that will add unique user ids to all Users. Args: job_entity: a Job entity with key_data set to [last_completed_user] """ key_data = job_entity.key_data user_fields = {'user_id': None} if len(key_data) == 1: # start where we left off user_fields['__key__ >'] = key_data[0] m_users = user_logic.getForFields(user_fields, limit=DEF_USER_STEP_SIZE) # set the default fields for the jobs we are going to create priority_group = priority_logic.getGroup(priority_logic.CONVERT) job_fields = { 'priority_group': priority_group, 'task_name': 'addUniqueUserIds' } job_query_fields = job_fields.copy() while m_users: # for each user create a adder job for user in m_users: job_query_fields['key_data'] = user.key() adder_job = job_logic.getForFields(job_query_fields, unique=True) if not adder_job: # this user doesn't have unique id yet job_fields['key_data'] = [user.key()] job_logic.updateOrCreateFromFields(job_fields) # update our own job last_user_key = m_users[-1].key() if len(key_data) == 1: key_data[0] = last_user_key else: key_data.append(last_user_key) updated_job_fields = {'key_data': key_data} job_logic.updateEntityProperties(job_entity, updated_job_fields) # rinse and repeat user_fields['__key__ >'] = last_user_key m_users = user_logic.getForFields(user_fields, limit=DEF_USER_STEP_SIZE) # we are finished return
def setupUniqueUserIdAdder(job_entity): """Job that setup jobs that will add unique user ids to all Users. Args: job_entity: a Job entity with key_data set to [last_completed_user] """ key_data = job_entity.key_data user_fields = {'user_id': None} if len(key_data) == 1: # start where we left off user_fields['__key__ >'] = key_data[0] m_users = user_logic.getForFields(user_fields, limit=DEF_USER_STEP_SIZE) # set the default fields for the jobs we are going to create priority_group = priority_logic.getGroup(priority_logic.CONVERT) job_fields = { 'priority_group': priority_group, 'task_name': 'addUniqueUserIds'} job_query_fields = job_fields.copy() while m_users: # for each user create a adder job for user in m_users: job_query_fields['key_data'] = user.key() adder_job = job_logic.getForFields(job_query_fields, unique=True) if not adder_job: # this user doesn't have unique id yet job_fields['key_data'] = [user.key()] job_logic.updateOrCreateFromFields(job_fields) # update our own job last_user_key = m_users[-1].key() if len(key_data) == 1: key_data[0] = last_user_key else: key_data.append(last_user_key) updated_job_fields = {'key_data': key_data} job_logic.updateEntityProperties(job_entity, updated_job_fields) # rinse and repeat user_fields['__key__ >'] = last_user_key m_users = user_logic.getForFields(user_fields, limit=DEF_USER_STEP_SIZE) # we are finished return
def setupStudentProposalMailing(job_entity): """Job that setup jobs that will mail students if they have been accepted in a program with a GSoC-like workflow. Args: job_entity: a Job entity with key_data set to [program, last_completed_student] """ from soc.cron.job import FatalJobError # retrieve the data we need to continue our work key_data = job_entity.key_data program_key = key_data[0] program_keyname = program_key.name() program_entity = program_logic.getFromKeyName(program_keyname) if not program_entity: raise FatalJobError('The program with key %s could not be found' % ( program_keyname)) student_fields = {'scope': program_entity} if len(key_data) >= 2: # start where we left off student_fields['__key__ >'] = key_data[1] students = student_logic.getForFields(student_fields, limit=DEF_STUDENT_STEP_SIZE) # set the default fields for the jobs we are going to create priority_group = priority_logic.getGroup(priority_logic.EMAIL) job_fields = { 'priority_group': priority_group, 'task_name': 'sendStudentProposalMail'} job_query_fields = job_fields.copy() while students: # for each student create a mailing job for student in students: job_query_fields['key_data'] = student.key() mail_job = job_logic.getForFields(job_query_fields, unique=True) if not mail_job: # this student did not receive mail yet job_fields['key_data'] = [student.key()] job_logic.updateOrCreateFromFields(job_fields) # update our own job last_student_key = students[-1].key() if len(key_data) >= 2: key_data[1] = last_student_key else: key_data.append(last_student_key) updated_job_fields = {'key_data': key_data} job_logic.updateEntityProperties(job_entity, updated_job_fields) # rinse and repeat student_fields['__key__ >'] = last_student_key students = student_logic.getForFields(student_fields, limit=DEF_STUDENT_STEP_SIZE) # we are finished return
def setupStudentProposalMailing(job_entity): """Job that setup jobs that will mail students if they have been accepted in a program with a GSoC-like workflow. Args: job_entity: a Job entity with key_data set to [program, last_completed_student] """ from soc.cron.job import FatalJobError # retrieve the data we need to continue our work key_data = job_entity.key_data program_key = key_data[0] program_keyname = program_key.name() program_entity = program_logic.getFromKeyName(program_keyname) if not program_entity: raise FatalJobError('The program with key %s could not be found' % (program_keyname)) student_fields = {'scope': program_entity} if len(key_data) >= 2: # start where we left off student_fields['__key__ >'] = key_data[1] students = student_logic.getForFields(student_fields, limit=DEF_STUDENT_STEP_SIZE) # set the default fields for the jobs we are going to create priority_group = priority_logic.getGroup(priority_logic.EMAIL) job_fields = { 'priority_group': priority_group, 'task_name': 'sendStudentProposalMail' } job_query_fields = job_fields.copy() while students: # for each student create a mailing job for student in students: job_query_fields['key_data'] = student.key() mail_job = job_logic.getForFields(job_query_fields, unique=True) if not mail_job: # this student did not receive mail yet job_fields['key_data'] = [student.key()] job_logic.updateOrCreateFromFields(job_fields) # update our own job last_student_key = students[-1].key() if len(key_data) >= 2: key_data[1] = last_student_key else: key_data.append(last_student_key) updated_job_fields = {'key_data': key_data} job_logic.updateEntityProperties(job_entity, updated_job_fields) # rinse and repeat student_fields['__key__ >'] = last_student_key students = student_logic.getForFields(student_fields, limit=DEF_STUDENT_STEP_SIZE) # we are finished return