Fossil SCM
Update the backoffice poller so that it invokes each backoffice at least once every hour - configurable using the --min command-line option.
Commit
e1d8cea28ae395235bc3267446c89fc5caefdd6fc431f3810159df57c4cbf892
Parent
a9cc104eb33ed52…
1 file changed
+23
-2
+23
-2
| --- src/backoffice.c | ||
| +++ src/backoffice.c | ||
| @@ -555,31 +555,40 @@ | ||
| 555 | 555 | ** |
| 556 | 556 | ** OPTIONS: |
| 557 | 557 | ** |
| 558 | 558 | ** --debug Show what this command is doing. |
| 559 | 559 | ** |
| 560 | +** --min N When polling, invoke backoffice at least | |
| 561 | +** once every N seconds even if the repository | |
| 562 | +** never changes. 0 or negative means disable | |
| 563 | +** this feature. Default: 3600 (once per hour). | |
| 564 | +** | |
| 560 | 565 | ** --nodelay Do not queue up or wait for a backoffice job |
| 561 | 566 | ** to complete. If no work is available or if |
| 562 | 567 | ** backoffice has run recently, return immediately. |
| 563 | 568 | ** The --nodelay option is implied if more than |
| 564 | 569 | ** one repository is listed on the command-line. |
| 565 | 570 | ** |
| 566 | 571 | ** --poll N Repeat backoffice calls for repositories that |
| 567 | 572 | ** change in appoximately N-second intervals. |
| 568 | 573 | ** N less than 1 turns polling off (the default). |
| 574 | +** Recommended polling interval: 60 seconds. | |
| 569 | 575 | ** |
| 570 | 576 | ** --trace Enable debugging output on stderr |
| 571 | 577 | */ |
| 572 | 578 | void backoffice_command(void){ |
| 573 | 579 | int nPoll; |
| 580 | + int nMin; | |
| 574 | 581 | const char *zPoll; |
| 575 | 582 | int bDebug = 0; |
| 576 | 583 | unsigned int nCmd = 0; |
| 577 | 584 | if( find_option("trace",0,0)!=0 ) g.fAnyTrace = 1; |
| 578 | 585 | if( find_option("nodelay",0,0)!=0 ) backofficeNoDelay = 1; |
| 579 | 586 | zPoll = find_option("poll",0,1); |
| 580 | 587 | nPoll = zPoll ? atoi(zPoll) : 0; |
| 588 | + zPoll = find_option("min",0,1); | |
| 589 | + nMin = zPoll ? atoi(zPoll) : 3600; | |
| 581 | 590 | bDebug = find_option("debug",0,0)!=0; |
| 582 | 591 | |
| 583 | 592 | /* Silently consume the -R or --repository flag, leaving behind its |
| 584 | 593 | ** argument. This is for legacy compatibility. Older versions of the |
| 585 | 594 | ** backoffice command only ran on a single repository that was specified |
| @@ -592,16 +601,25 @@ | ||
| 592 | 601 | ** or we are polling. In either case, each backoffice should be run |
| 593 | 602 | ** using a separate sub-process */ |
| 594 | 603 | int i; |
| 595 | 604 | time_t iNow = 0; |
| 596 | 605 | time_t ix; |
| 606 | + i64 *aLastRun = fossil_malloc( sizeof(i64)*g.argc ); | |
| 607 | + memset(aLastRun, 0, sizeof(i64)*g.argc ); | |
| 597 | 608 | while( 1 /* exit via "break;" */){ |
| 598 | 609 | time_t iNext = time(0); |
| 599 | 610 | for(i=2; i<g.argc; i++){ |
| 600 | 611 | Blob cmd; |
| 601 | - if( !file_isfile(g.argv[i], ExtFILE) ) continue; | |
| 602 | - if( iNow && iNow>file_mtime(g.argv[i],ExtFILE) ) continue; | |
| 612 | + if( !file_isfile(g.argv[i], ExtFILE) ){ | |
| 613 | + continue; /* Repo no longer exists. Ignore it. */ | |
| 614 | + } | |
| 615 | + if( iNow | |
| 616 | + && iNow>file_mtime(g.argv[i], ExtFILE) | |
| 617 | + && (nMin<=0 || aLastRun[i]+nMin>iNow) | |
| 618 | + ){ | |
| 619 | + continue; /* Not yet time to run this one */ | |
| 620 | + } | |
| 603 | 621 | blob_init(&cmd, 0, 0); |
| 604 | 622 | blob_append_escaped_arg(&cmd, g.nameOfExe); |
| 605 | 623 | blob_append(&cmd, " backoffice --nodelay", -1); |
| 606 | 624 | if( g.fAnyTrace ){ |
| 607 | 625 | blob_append(&cmd, " --trace", -1); |
| @@ -610,10 +628,11 @@ | ||
| 610 | 628 | nCmd++; |
| 611 | 629 | if( bDebug ){ |
| 612 | 630 | fossil_print("COMMAND[%u]: %s\n", nCmd, blob_str(&cmd)); |
| 613 | 631 | } |
| 614 | 632 | fossil_system(blob_str(&cmd)); |
| 633 | + aLastRun[i] = iNext; | |
| 615 | 634 | blob_reset(&cmd); |
| 616 | 635 | } |
| 617 | 636 | if( nPoll<1 ) break; |
| 618 | 637 | iNow = iNext; |
| 619 | 638 | ix = time(0); |
| @@ -622,10 +641,12 @@ | ||
| 622 | 641 | if( bDebug )fossil_print("SLEEP: %lld\n", nMS); |
| 623 | 642 | sqlite3_sleep((int)nMS); |
| 624 | 643 | } |
| 625 | 644 | } |
| 626 | 645 | }else{ |
| 646 | + /* Not polling and only one repository named. Backoffice is run | |
| 647 | + ** once by this process, which then exits */ | |
| 627 | 648 | if( g.argc==3 ){ |
| 628 | 649 | g.zRepositoryOption = g.argv[2]; |
| 629 | 650 | g.argc--; |
| 630 | 651 | } |
| 631 | 652 | db_find_and_open_repository(0,0); |
| 632 | 653 |
| --- src/backoffice.c | |
| +++ src/backoffice.c | |
| @@ -555,31 +555,40 @@ | |
| 555 | ** |
| 556 | ** OPTIONS: |
| 557 | ** |
| 558 | ** --debug Show what this command is doing. |
| 559 | ** |
| 560 | ** --nodelay Do not queue up or wait for a backoffice job |
| 561 | ** to complete. If no work is available or if |
| 562 | ** backoffice has run recently, return immediately. |
| 563 | ** The --nodelay option is implied if more than |
| 564 | ** one repository is listed on the command-line. |
| 565 | ** |
| 566 | ** --poll N Repeat backoffice calls for repositories that |
| 567 | ** change in appoximately N-second intervals. |
| 568 | ** N less than 1 turns polling off (the default). |
| 569 | ** |
| 570 | ** --trace Enable debugging output on stderr |
| 571 | */ |
| 572 | void backoffice_command(void){ |
| 573 | int nPoll; |
| 574 | const char *zPoll; |
| 575 | int bDebug = 0; |
| 576 | unsigned int nCmd = 0; |
| 577 | if( find_option("trace",0,0)!=0 ) g.fAnyTrace = 1; |
| 578 | if( find_option("nodelay",0,0)!=0 ) backofficeNoDelay = 1; |
| 579 | zPoll = find_option("poll",0,1); |
| 580 | nPoll = zPoll ? atoi(zPoll) : 0; |
| 581 | bDebug = find_option("debug",0,0)!=0; |
| 582 | |
| 583 | /* Silently consume the -R or --repository flag, leaving behind its |
| 584 | ** argument. This is for legacy compatibility. Older versions of the |
| 585 | ** backoffice command only ran on a single repository that was specified |
| @@ -592,16 +601,25 @@ | |
| 592 | ** or we are polling. In either case, each backoffice should be run |
| 593 | ** using a separate sub-process */ |
| 594 | int i; |
| 595 | time_t iNow = 0; |
| 596 | time_t ix; |
| 597 | while( 1 /* exit via "break;" */){ |
| 598 | time_t iNext = time(0); |
| 599 | for(i=2; i<g.argc; i++){ |
| 600 | Blob cmd; |
| 601 | if( !file_isfile(g.argv[i], ExtFILE) ) continue; |
| 602 | if( iNow && iNow>file_mtime(g.argv[i],ExtFILE) ) continue; |
| 603 | blob_init(&cmd, 0, 0); |
| 604 | blob_append_escaped_arg(&cmd, g.nameOfExe); |
| 605 | blob_append(&cmd, " backoffice --nodelay", -1); |
| 606 | if( g.fAnyTrace ){ |
| 607 | blob_append(&cmd, " --trace", -1); |
| @@ -610,10 +628,11 @@ | |
| 610 | nCmd++; |
| 611 | if( bDebug ){ |
| 612 | fossil_print("COMMAND[%u]: %s\n", nCmd, blob_str(&cmd)); |
| 613 | } |
| 614 | fossil_system(blob_str(&cmd)); |
| 615 | blob_reset(&cmd); |
| 616 | } |
| 617 | if( nPoll<1 ) break; |
| 618 | iNow = iNext; |
| 619 | ix = time(0); |
| @@ -622,10 +641,12 @@ | |
| 622 | if( bDebug )fossil_print("SLEEP: %lld\n", nMS); |
| 623 | sqlite3_sleep((int)nMS); |
| 624 | } |
| 625 | } |
| 626 | }else{ |
| 627 | if( g.argc==3 ){ |
| 628 | g.zRepositoryOption = g.argv[2]; |
| 629 | g.argc--; |
| 630 | } |
| 631 | db_find_and_open_repository(0,0); |
| 632 |
| --- src/backoffice.c | |
| +++ src/backoffice.c | |
| @@ -555,31 +555,40 @@ | |
| 555 | ** |
| 556 | ** OPTIONS: |
| 557 | ** |
| 558 | ** --debug Show what this command is doing. |
| 559 | ** |
| 560 | ** --min N When polling, invoke backoffice at least |
| 561 | ** once every N seconds even if the repository |
| 562 | ** never changes. 0 or negative means disable |
| 563 | ** this feature. Default: 3600 (once per hour). |
| 564 | ** |
| 565 | ** --nodelay Do not queue up or wait for a backoffice job |
| 566 | ** to complete. If no work is available or if |
| 567 | ** backoffice has run recently, return immediately. |
| 568 | ** The --nodelay option is implied if more than |
| 569 | ** one repository is listed on the command-line. |
| 570 | ** |
| 571 | ** --poll N Repeat backoffice calls for repositories that |
| 572 | ** change in appoximately N-second intervals. |
| 573 | ** N less than 1 turns polling off (the default). |
| 574 | ** Recommended polling interval: 60 seconds. |
| 575 | ** |
| 576 | ** --trace Enable debugging output on stderr |
| 577 | */ |
| 578 | void backoffice_command(void){ |
| 579 | int nPoll; |
| 580 | int nMin; |
| 581 | const char *zPoll; |
| 582 | int bDebug = 0; |
| 583 | unsigned int nCmd = 0; |
| 584 | if( find_option("trace",0,0)!=0 ) g.fAnyTrace = 1; |
| 585 | if( find_option("nodelay",0,0)!=0 ) backofficeNoDelay = 1; |
| 586 | zPoll = find_option("poll",0,1); |
| 587 | nPoll = zPoll ? atoi(zPoll) : 0; |
| 588 | zPoll = find_option("min",0,1); |
| 589 | nMin = zPoll ? atoi(zPoll) : 3600; |
| 590 | bDebug = find_option("debug",0,0)!=0; |
| 591 | |
| 592 | /* Silently consume the -R or --repository flag, leaving behind its |
| 593 | ** argument. This is for legacy compatibility. Older versions of the |
| 594 | ** backoffice command only ran on a single repository that was specified |
| @@ -592,16 +601,25 @@ | |
| 601 | ** or we are polling. In either case, each backoffice should be run |
| 602 | ** using a separate sub-process */ |
| 603 | int i; |
| 604 | time_t iNow = 0; |
| 605 | time_t ix; |
| 606 | i64 *aLastRun = fossil_malloc( sizeof(i64)*g.argc ); |
| 607 | memset(aLastRun, 0, sizeof(i64)*g.argc ); |
| 608 | while( 1 /* exit via "break;" */){ |
| 609 | time_t iNext = time(0); |
| 610 | for(i=2; i<g.argc; i++){ |
| 611 | Blob cmd; |
| 612 | if( !file_isfile(g.argv[i], ExtFILE) ){ |
| 613 | continue; /* Repo no longer exists. Ignore it. */ |
| 614 | } |
| 615 | if( iNow |
| 616 | && iNow>file_mtime(g.argv[i], ExtFILE) |
| 617 | && (nMin<=0 || aLastRun[i]+nMin>iNow) |
| 618 | ){ |
| 619 | continue; /* Not yet time to run this one */ |
| 620 | } |
| 621 | blob_init(&cmd, 0, 0); |
| 622 | blob_append_escaped_arg(&cmd, g.nameOfExe); |
| 623 | blob_append(&cmd, " backoffice --nodelay", -1); |
| 624 | if( g.fAnyTrace ){ |
| 625 | blob_append(&cmd, " --trace", -1); |
| @@ -610,10 +628,11 @@ | |
| 628 | nCmd++; |
| 629 | if( bDebug ){ |
| 630 | fossil_print("COMMAND[%u]: %s\n", nCmd, blob_str(&cmd)); |
| 631 | } |
| 632 | fossil_system(blob_str(&cmd)); |
| 633 | aLastRun[i] = iNext; |
| 634 | blob_reset(&cmd); |
| 635 | } |
| 636 | if( nPoll<1 ) break; |
| 637 | iNow = iNext; |
| 638 | ix = time(0); |
| @@ -622,10 +641,12 @@ | |
| 641 | if( bDebug )fossil_print("SLEEP: %lld\n", nMS); |
| 642 | sqlite3_sleep((int)nMS); |
| 643 | } |
| 644 | } |
| 645 | }else{ |
| 646 | /* Not polling and only one repository named. Backoffice is run |
| 647 | ** once by this process, which then exits */ |
| 648 | if( g.argc==3 ){ |
| 649 | g.zRepositoryOption = g.argv[2]; |
| 650 | g.argc--; |
| 651 | } |
| 652 | db_find_and_open_repository(0,0); |
| 653 |