Changeset 13199


Ignore:
Timestamp:
15 Aug 2015, 20:08:02 (9 years ago)
Author:
Henrik Bettermann
Message:

Do only allow one running export job.

Location:
main/waeup.kofa/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/CHANGES.txt

    r13198 r13199  
    441.3.2.dev0 (unreleased)
    55=======================
     6
     7* Do only allow one running export job.
    68
    79* Add switch to disable all exports.
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/pages.py

    r13198 r13199  
    246246        entries.append(new_entry)
    247247    return entries
     248
     249def running_jobs(view):
     250    """True if any job is running.
     251    """
     252    job_entries = view.context.get_running_export_jobs()
     253    job_manager = getUtility(IJobManager)
     254    entries = []
     255    for entry in job_entries:
     256        job = job_manager.get(entry[0])
     257        status = job.finished and 'ready' or 'running'
     258        status = job.failed and 'FAILED' or status
     259        if status == 'running':
     260            return True
     261    return False
    248262
    249263def getImporters(context):
     
    17521766                self.entries = doll_up(self, user=None)
    17531767                return
     1768            if running_jobs(self):
     1769                self.flash(_(
     1770                    "Sorry, another export job is running. "
     1771                    "Please try again later."), type='danger')
     1772                self.entries = doll_up(self, user=None)
     1773                return
    17541774            job_id = self.context.start_export_job(
    17551775                exporter, self.request.principal.id)
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/tests/test_browser.py

    r13198 r13199  
    212212        self.browser.getControl(name="exporter").value = ['faculties']
    213213        self.browser.getControl("Create CSV file").click()
    214         self.assertEqual(self.browser.headers['Status'], '200 Ok')
     214        # we can trigger export file creation only once
     215        self.browser.getControl(name="exporter").value = ['departments']
     216        self.browser.getControl("Create CSV file").click()
     217        self.assertTrue('Sorry, another export job is running.'
     218                         in self.browser.contents)
     219        self.wait_for_export_job_completed()
     220        self.assertEqual(len(self.app['datacenter'].running_exports), 1)
     221        self.browser.getControl(name="exporter").value = ['departments']
     222        self.browser.getControl("Create CSV file").click()
     223        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     224        self.assertEqual(len(self.app['datacenter'].running_exports), 2)
     225        # The second job is running
     226        self.assertTrue('<img src="/static/img/actionicon_reload.png" />'
     227                         in self.browser.contents)
    215228        self.cleanup_run_job() # make sure to remove temp dirs
     229        # Also the second job must be cleaned up
     230        manager = getUtility(IJobManager)
     231        job_id = self.app['datacenter'].running_exports[1][0]
     232        job = manager.get(job_id)
     233        wait_for_result(job)
     234        if os.path.exists(job.result):
     235            shutil.rmtree(os.path.dirname(job.result))
    216236        return
    217237
     
    363383            'password,state,history,certcode,is_postgrad,current_level,'
    364384            'current_session\r\n')
    365         self.cleanup_run_job()
    366385        logfile = os.path.join(
    367386            self.app['datacenter'].storage, 'logs', 'datacenter.log')
     
    376395            '- downloaded: WAeUP.Kofa_students_%s.csv, job_id=%s'
    377396            % (job_id, job_id) in logcontent)
     397        self.cleanup_run_job()
    378398        return
    379399
Note: See TracChangeset for help on using the changeset viewer.