示例#1
0
    def post(self):
        job = models.ProcessingJob.get(self.request.get('job_key'))

        try:
            description = "Sends the unsent results of the Will Rice election."
            # Assertion here to ensure that the developer is running the right
            # task
            assert(job.description == description)

            ### Processing begin ###

            election = models.Election.gql("WHERE name=:1", "Round 3 Spring Elections").get()

            admin_emails = []
            for org_admin in election.organization.organization_admins:
                admin_emails.append(org_admin.admin.email)

            report_results.email_report(admin_emails, election)
            
            ### Processing end ###

            job.status = "complete"
        finally:
            if job.status != "complete":
                job.status = "failed"
            job.ended = datetime.datetime.now()
            job.put()
示例#2
0
    def post(self):
        job = models.ProcessingJob.get(self.request.get('job_key'))

        try:
            description = "Sends the unsent results of the Will Rice election."
            # Assertion here to ensure that the developer is running the right
            # task
            assert (job.description == description)

            ### Processing begin ###

            election = models.Election.gql("WHERE name=:1",
                                           "Round 3 Spring Elections").get()

            admin_emails = []
            for org_admin in election.organization.organization_admins:
                admin_emails.append(org_admin.admin.email)

            report_results.email_report(admin_emails, election)

            ### Processing end ###

            job.status = "complete"
        finally:
            if job.status != "complete":
                job.status = "failed"
            job.ended = datetime.datetime.now()
            job.put()
示例#3
0
    def compute_results(self, election):
        # Assert validity
        if not election:
            logging.error('Election not found.')
            return
        if election.end > datetime.now():
            logging.error('Election is still open.')
            return
        if election.result_computed:
            logging.error('Election results already computed.')
            return

        logging.info('Computing results for election: %s, organization: %s.', 
                        election.name, election.organization.name)

        total_ballot_count = 0
        for election_position in election.election_positions:
            total_ballot_count += election_position.ballots.count()
        if total_ballot_count > 2500:
            large_election = True
        else:
            large_election = False

        all_computed = True
        for election_position in election.election_positions:
            if not election_position.result_computed:
                all_computed = False

                if large_election:
                    # Enqueue a task for computing results
                    task_name = 'compute-result-' + str(election_position.key())
                    retry_options = taskqueue.TaskRetryOptions(task_retry_limit=0)
                    taskqueue.add(
                        name=task_name,
                        url='/tasks/position-results',
                        params={
                            'election_position_key': str(election_position.key())},
                        retry_options=retry_options
                    )
                else:
                    election_position.compute_winners()


        if all_computed:
            election.result_computed = True
            election.put()
            logging.info('Computed results for election: %s, organization: %s.',
                            election.name, election.organization.name)

            if not large_election:
                admin_emails = []
                for org_admin in election.organization.organization_admins:
                    admin_emails.append(org_admin.admin.email)
                report_results.email_report(admin_emails, election)