Beispiel #1
0
def check_problem_instance_state(env, suspend_init_tests=None, **kwargs):
    suspend = False
    with transaction.atomic():
        if (_is_suspended(env['problem_instance_id'], suspend_init_tests)
                and not _is_hidden_rejudge(env)
                and not _is_admin_submission(env)
                and not _is_model_solution(env)):
            mark_job_state(env, 'SUSPENDED')
            suspend = True
    if suspend:
        raise Ignore
    return env
Beispiel #2
0
def check_problem_instance_state(env, suspend_init_tests=None, **kwargs):
    suspend = False
    with transaction.atomic():
        if _is_suspended(env['problem_instance_id'], suspend_init_tests) and \
                not _is_hidden_rejudge(env) and \
                not _is_admin_submission(env) and \
                not _is_model_solution(env):
            mark_job_state(env, 'SUSPENDED')
            suspend = True
    if suspend:
        raise Ignore
    return env
Beispiel #3
0
    def test_revoke(self):
        """Test if a submit revokes properly."""
        job_id = 'dummy'
        env = {}
        env['job_id'] = job_id
        env['submission_id'] = 1
        env['celery_task_id'] = job_id

        submission = Submission.objects.get(pk=1)
        qs = QueuedJob(submission=submission,
                       state='CANCELLED',
                       celery_task_id=job_id,
                       job_id=job_id)
        qs.save()

        self.assertFalse(mark_job_state(env, state='PROGRESS'))
Beispiel #4
0
def delay_environ(environ, **evalmgr_extra_args):
    """Inserts environ into evalmgr queue with marking it as queued, resuming
    it if it should be. Returns associated async result, or None when job
    was already resumed before (or was cancelled).

    Requires to be called from transaction.
    """
    if 'saved_environ_id' in environ:
        environ = _resume_job(environ)
        if environ is None:
            return None
    if not mark_job_state(environ, 'QUEUED'):
        return None
    async_result = evalmgr_job.apply_async((environ, ), **evalmgr_extra_args)
    QueuedJob.objects.filter(job_id=environ['job_id']).update(
        celery_task_id=async_result.id)
    return async_result
Beispiel #5
0
def delay_environ(environ, **evalmgr_extra_args):
    """Inserts environ into evalmgr queue with marking it as queued, resuming
       it if it should be. Returns associated async result, or None when job
       was already resumed before (or was cancelled).

       Requires to be called from transaction.
    """
    if 'saved_environ_id' in environ:
        environ = _resume_job(environ)
        if environ is None:
            return None
    if not mark_job_state(environ, 'QUEUED'):
        return None
    async_result = evalmgr_job.apply_async((environ,), **evalmgr_extra_args)
    QueuedJob.objects.filter(
            job_id=environ['job_id']).update(celery_task_id=async_result.id)
    return async_result
Beispiel #6
0
    def test_revoke(self):
        """Test if a submit revokes properly."""
        job_id = 'dummy'
        env = {}
        env['job_id'] = job_id
        env['submission_id'] = 1
        env['celery_task_id'] = job_id

        submission = Submission.objects.get(pk=1)
        qs = QueuedJob(
                submission=submission,
                state='CANCELLED',
                celery_task_id=job_id,
                job_id=job_id)
        qs.save()

        self.assertFalse(mark_job_state(env, state='PROGRESS'))
Beispiel #7
0
def _transfer_job(environ, transfer_func, transfer_kwargs):
    with transaction.atomic():
        marked = mark_job_state(environ, 'WAITING')
        if marked:
            # Save without ``environ['transfer']`` or
            # ``environ['saved_environ_id']``.
            saved_environ = SavedEnviron.save_environ(environ)
            environ['saved_environ_id'] = saved_environ.id
    if not marked:
        raise Ignore
    try:
        import_string(transfer_func)(environ, **transfer_kwargs)
    # pylint: disable=broad-except
    except Exception:
        with transaction.atomic():
            SavedEnviron.objects.filter(
                id=environ.pop('saved_environ_id')).delete()
        raise
    return environ
Beispiel #8
0
def _transfer_job(environ, transfer_func, transfer_kwargs):
    with transaction.atomic():
        marked = mark_job_state(environ, 'WAITING')
        if marked:
            # Save without ``environ['transfer']`` or
            # ``environ['saved_environ_id']``.
            saved_environ = SavedEnviron.save_environ(environ)
            environ['saved_environ_id'] = saved_environ.id
    if not marked:
        raise Ignore
    try:
        import_string(transfer_func)(environ, **transfer_kwargs)
    # pylint: disable=broad-except
    except Exception:
        with transaction.atomic():
            SavedEnviron.objects.filter(
                    id=environ.pop('saved_environ_id')).delete()
        raise
    return environ
Beispiel #9
0
def _mark_job_state(environ, state):
    with transaction.atomic():
        marked = mark_job_state(environ, state)
    if not marked:
        raise Ignore
Beispiel #10
0
def _mark_job_state(environ, state):
    with transaction.atomic():
        marked = mark_job_state(environ, state)
    if not marked:
        raise Ignore