Projet

Général

Profil

0001-workflows-allow-generated-timeout-to-be-in-human-tim.patch

Frédéric Péters, 02 novembre 2021 10:34

Télécharger (4,48 ko)

Voir les différences:

Subject: [PATCH] workflows: allow generated timeout to be in "human time"
 (#54930)

 tests/workflow/test_all.py | 64 ++++++++++++++++++++++++++++++++++++++
 wcs/wf/jump.py             | 23 ++++++++++++--
 2 files changed, 84 insertions(+), 3 deletions(-)
tests/workflow/test_all.py
2430 2430
    _apply_timeouts(two_pubs)
2431 2431

  
2432 2432

  
2433
def test_timeout_with_humantime_template(two_pubs):
2434
    workflow = Workflow(name='timeout')
2435
    st1 = workflow.add_status('Status1', 'st1')
2436
    workflow.add_status('Status2', 'st2')
2437

  
2438
    jump = JumpWorkflowStatusItem()
2439
    jump.id = '_jump'
2440
    jump.by = ['_submitter', '_receiver']
2441
    jump.timeout = '{{ 30 }} minutes'
2442
    jump.status = 'st2'
2443
    st1.items.append(jump)
2444
    jump.parent = st1
2445

  
2446
    workflow.store()
2447

  
2448
    formdef = FormDef()
2449
    formdef.name = 'baz'
2450
    formdef.fields = []
2451
    formdef.workflow_id = workflow.id
2452
    assert formdef.get_workflow().id == workflow.id
2453
    formdef.store()
2454

  
2455
    formdata = formdef.data_class()()
2456
    formdata.just_created()
2457
    formdata.store()
2458
    formdata_id = formdata.id
2459

  
2460
    _apply_timeouts(two_pubs)
2461
    assert formdef.data_class().get(formdata_id).status == 'wf-st1'  # no change
2462

  
2463
    rewind(formdata, seconds=40 * 60)
2464
    formdata.store()
2465
    _apply_timeouts(two_pubs)
2466
    assert formdef.data_class().get(formdata_id).status == 'wf-st2'
2467

  
2468
    # invalid timeout value
2469
    jump.timeout = '{{ 30 }} plop'
2470
    workflow.store()
2471
    formdef.refresh_from_storage()
2472

  
2473
    formdata = formdef.data_class()()
2474
    formdata.just_created()
2475
    formdata.store()
2476
    formdata_id = formdata.id
2477

  
2478
    if two_pubs.is_using_postgresql():
2479
        two_pubs.loggederror_class.wipe()
2480

  
2481
    rewind(formdata, seconds=40 * 60)
2482
    formdata.store()
2483
    _apply_timeouts(two_pubs)
2484
    assert formdef.data_class().get(formdata_id).status == 'wf-st1'  # no change
2485

  
2486
    if two_pubs.is_using_postgresql():
2487
        assert two_pubs.loggederror_class.count() == 1
2488
        logged_error = two_pubs.loggederror_class.select()[0]
2489
        assert logged_error.summary == "Error in timeout value ('30 plop')"
2490

  
2491

  
2433 2492
def test_legacy_timeout(pub):
2434 2493
    workflow = Workflow(name='timeout')
2435 2494
    st1 = workflow.add_status('Status1', 'st1')
......
2541 2600
        pytest.skip('this requires SQL')
2542 2601
        return
2543 2602

  
2603
    FormDef.wipe()
2604
    Workflow.wipe()
2605

  
2544 2606
    workflow = Workflow(name='jump-mark')
2545 2607
    st1 = workflow.add_status('Status1', 'st1')
2546 2608

  
......
5482 5544
    formdef.workflow_id = workflow.id
5483 5545
    formdef.store()
5484 5546

  
5547
    formdef.data_class().wipe()
5548

  
5485 5549
    formdata1 = formdef.data_class()()
5486 5550
    formdata1.data = {'1': 'foo'}
5487 5551
    formdata1.just_created()
wcs/wf/jump.py
278 278
            must_jump = must_jump and triggered
279 279

  
280 280
        if self.timeout:
281
            timeout = float(self.compute(self.timeout))
281
            timeout_str = self.compute(self.timeout)
282
            try:
283
                timeout_seconds = float(timeout_str)
284
            except ValueError:
285
                try:
286
                    timeout_seconds = humanduration2seconds(timeout_str)
287
                except ValueError:
288
                    timeout_seconds = 0
289
                if timeout_seconds == 0:
290
                    get_publisher().record_error(
291
                        _('Error in timeout value (%r)') % timeout_str,
292
                        formdata=formdata,
293
                        formdef=formdata.formdef,
294
                        workflow=formdata.formdef.workflow,
295
                        notify=False,
296
                        record=True,
297
                    )
298
                    must_jump = False
282 299
            last = formdata.last_update_time
283
            if last:
300
            if last and timeout_seconds:
284 301
                diff = time.time() - time.mktime(last)
285
                must_jump = (diff > timeout) and must_jump
302
                must_jump = (diff > timeout_seconds) and must_jump
286 303

  
287 304
        return must_jump
288 305

  
289
-