Fossil SCM
Improvements to backoffice polling using the "fossil backoffice" command.
Commit
75b76efbba2a5c9b7981f3ae579ab295885cd50a357d12cb383647ac23017d27
Parent
2a4322d8fd55478…
1 file changed
+42
-10
+42
-10
| --- src/backoffice.c | ||
| +++ src/backoffice.c | ||
| @@ -145,10 +145,15 @@ | ||
| 145 | 145 | /* |
| 146 | 146 | ** Write backoffice log messages on this BLOB. to this connection: |
| 147 | 147 | */ |
| 148 | 148 | static Blob *backofficeBlob = 0; |
| 149 | 149 | |
| 150 | +/* | |
| 151 | +** Non-zero for extra logging detail. | |
| 152 | +*/ | |
| 153 | +static int backofficeLogDetail = 0; | |
| 154 | + | |
| 150 | 155 | /* End of state variables |
| 151 | 156 | ****************************************************************************/ |
| 152 | 157 | |
| 153 | 158 | /* |
| 154 | 159 | ** This function emits a diagnostic message related to the processing in |
| @@ -597,20 +602,25 @@ | ||
| 597 | 602 | struct timeval sStart, sEnd; |
| 598 | 603 | #endif |
| 599 | 604 | if( zLog==0 ) zLog = db_get("backoffice-logfile",0); |
| 600 | 605 | if( zLog && zLog[0] && (backofficeFILE = fossil_fopen(zLog,"a"))!=0 ){ |
| 601 | 606 | int i; |
| 602 | - char *zName = db_get("project-name",""); | |
| 607 | + char *zName = db_get("project-name",0); | |
| 603 | 608 | #if !defined(_WIN32) |
| 604 | 609 | gettimeofday(&sStart, 0); |
| 605 | 610 | signal(SIGSEGV, backoffice_signal_handler); |
| 606 | 611 | signal(SIGABRT, backoffice_signal_handler); |
| 607 | 612 | signal(SIGFPE, backoffice_signal_handler); |
| 608 | 613 | signal(SIGILL, backoffice_signal_handler); |
| 609 | 614 | #endif |
| 610 | - /* Convert all spaces in the "project-name" into dashes */ | |
| 611 | - for(i=0; zName[i]; i++){ if( zName[i]==' ' ) zName[i] = '-'; } | |
| 615 | + if( zName==0 ){ | |
| 616 | + zName = (char*)file_tail(g.zRepositoryName); | |
| 617 | + if( zName==0 ) zName = "(unnamed)"; | |
| 618 | + }else{ | |
| 619 | + /* Convert all spaces in the "project-name" into dashes */ | |
| 620 | + for(i=0; zName[i]; i++){ if( zName[i]==' ' ) zName[i] = '-'; } | |
| 621 | + } | |
| 612 | 622 | blob_init(&log, 0, 0); |
| 613 | 623 | backofficeBlob = &log; |
| 614 | 624 | blob_appendf(&log, "%s %s", db_text(0, "SELECT datetime('now')"), zName); |
| 615 | 625 | } |
| 616 | 626 | |
| @@ -620,16 +630,19 @@ | ||
| 620 | 630 | nThis = smtp_cleanup(); |
| 621 | 631 | if( nThis ){ backoffice_log("%d SMTPs", nThis); nTotal += nThis; } |
| 622 | 632 | |
| 623 | 633 | /* Close the log */ |
| 624 | 634 | if( backofficeFILE ){ |
| 625 | - if( nTotal==0 ) backoffice_log("no-op"); | |
| 635 | + if( nTotal || backofficeLogDetail ){ | |
| 636 | + if( nTotal==0 ) backoffice_log("no-op"); | |
| 626 | 637 | #if !defined(_WIN32) |
| 627 | - gettimeofday(&sEnd,0); | |
| 628 | - backoffice_log("elapse-time %d us", tvms(&sEnd) - tvms(&sStart)); | |
| 638 | + gettimeofday(&sEnd,0); | |
| 639 | + backoffice_log("elapse-time %d us", tvms(&sEnd) - tvms(&sStart)); | |
| 629 | 640 | #endif |
| 630 | - fprintf(backofficeFILE, "%s\n", blob_str(backofficeBlob)); | |
| 641 | + fprintf(backofficeFILE, "%s\n", blob_str(backofficeBlob)); | |
| 642 | + } | |
| 643 | + fclose(backofficeFILE); | |
| 631 | 644 | } |
| 632 | 645 | } |
| 633 | 646 | |
| 634 | 647 | /* |
| 635 | 648 | ** COMMAND: backoffice* |
| @@ -647,11 +660,11 @@ | ||
| 647 | 660 | ** If only a single repository is named and --poll is omitted, the the |
| 648 | 661 | ** backoffice work is done in-process. But if there are multiple respositories |
| 649 | 662 | ** or if --poll is used, a separate sub-process is started for each poll of |
| 650 | 663 | ** each repository. |
| 651 | 664 | ** |
| 652 | -** OPTIONS: | |
| 665 | +** Standard options: | |
| 653 | 666 | ** |
| 654 | 667 | ** --debug Show what this command is doing. |
| 655 | 668 | ** |
| 656 | 669 | ** --logfile FILE Append a log of backoffice actions onto FILE. |
| 657 | 670 | ** |
| @@ -661,34 +674,40 @@ | ||
| 661 | 674 | ** this feature. Default: 3600 (once per hour). |
| 662 | 675 | ** |
| 663 | 676 | ** --nodelay Do not queue up or wait for a backoffice job |
| 664 | 677 | ** to complete. If no work is available or if |
| 665 | 678 | ** backoffice has run recently, return immediately. |
| 666 | -** The --nodelay option is implied if more than | |
| 667 | -** one repository is listed on the command-line. | |
| 668 | 679 | ** |
| 669 | 680 | ** --poll N Repeat backoffice calls for repositories that |
| 670 | 681 | ** change in appoximately N-second intervals. |
| 671 | 682 | ** N less than 1 turns polling off (the default). |
| 672 | 683 | ** Recommended polling interval: 60 seconds. |
| 673 | 684 | ** |
| 674 | 685 | ** --trace Enable debugging output on stderr |
| 686 | +** | |
| 687 | +** Options intended for internal use only which may change or be | |
| 688 | +** discontinued in a future release: | |
| 689 | +** | |
| 690 | +** --nolease Always run backoffice, even if there is a lease | |
| 691 | +** conflict. This option implies --nodelay. | |
| 675 | 692 | */ |
| 676 | 693 | void backoffice_command(void){ |
| 677 | 694 | int nPoll; |
| 678 | 695 | int nMin; |
| 679 | 696 | const char *zPoll; |
| 680 | 697 | int bDebug = 0; |
| 698 | + int bNoLease = 0; | |
| 681 | 699 | unsigned int nCmd = 0; |
| 682 | 700 | if( find_option("trace",0,0)!=0 ) g.fAnyTrace = 1; |
| 683 | 701 | if( find_option("nodelay",0,0)!=0 ) backofficeNoDelay = 1; |
| 684 | 702 | backofficeLogfile = find_option("logfile",0,1); |
| 685 | 703 | zPoll = find_option("poll",0,1); |
| 686 | 704 | nPoll = zPoll ? atoi(zPoll) : 0; |
| 687 | 705 | zPoll = find_option("min",0,1); |
| 688 | 706 | nMin = zPoll ? atoi(zPoll) : 3600; |
| 689 | 707 | bDebug = find_option("debug",0,0)!=0; |
| 708 | + bNoLease = find_option("nolease",0,0)!=0; | |
| 690 | 709 | |
| 691 | 710 | /* Silently consume the -R or --repository flag, leaving behind its |
| 692 | 711 | ** argument. This is for legacy compatibility. Older versions of the |
| 693 | 712 | ** backoffice command only ran on a single repository that was specified |
| 694 | 713 | ** using the -R option. */ |
| @@ -721,10 +740,20 @@ | ||
| 721 | 740 | blob_append_escaped_arg(&cmd, g.nameOfExe); |
| 722 | 741 | blob_append(&cmd, " backoffice --nodelay", -1); |
| 723 | 742 | if( g.fAnyTrace ){ |
| 724 | 743 | blob_append(&cmd, " --trace", -1); |
| 725 | 744 | } |
| 745 | + if( bDebug ){ | |
| 746 | + blob_append(&cmd, " --debug", -1); | |
| 747 | + } | |
| 748 | + if( nPoll>0 ){ | |
| 749 | + blob_append(&cmd, " --nolease", -1); | |
| 750 | + } | |
| 751 | + if( backofficeLogfile ){ | |
| 752 | + blob_append(&cmd, " --logfile", -1); | |
| 753 | + blob_append_escaped_arg(&cmd, backofficeLogfile); | |
| 754 | + } | |
| 726 | 755 | blob_append_escaped_arg(&cmd, g.argv[i]); |
| 727 | 756 | nCmd++; |
| 728 | 757 | if( bDebug ){ |
| 729 | 758 | fossil_print("COMMAND[%u]: %s\n", nCmd, blob_str(&cmd)); |
| 730 | 759 | } |
| @@ -748,10 +777,13 @@ | ||
| 748 | 777 | g.zRepositoryOption = g.argv[2]; |
| 749 | 778 | g.argc--; |
| 750 | 779 | } |
| 751 | 780 | db_find_and_open_repository(0,0); |
| 752 | 781 | if( bDebug ){ |
| 782 | + backofficeLogDetail = 1; | |
| 783 | + } | |
| 784 | + if( bNoLease ){ | |
| 753 | 785 | backoffice_work(); |
| 754 | 786 | }else{ |
| 755 | 787 | backoffice_thread(); |
| 756 | 788 | } |
| 757 | 789 | } |
| 758 | 790 |
| --- src/backoffice.c | |
| +++ src/backoffice.c | |
| @@ -145,10 +145,15 @@ | |
| 145 | /* |
| 146 | ** Write backoffice log messages on this BLOB. to this connection: |
| 147 | */ |
| 148 | static Blob *backofficeBlob = 0; |
| 149 | |
| 150 | /* End of state variables |
| 151 | ****************************************************************************/ |
| 152 | |
| 153 | /* |
| 154 | ** This function emits a diagnostic message related to the processing in |
| @@ -597,20 +602,25 @@ | |
| 597 | struct timeval sStart, sEnd; |
| 598 | #endif |
| 599 | if( zLog==0 ) zLog = db_get("backoffice-logfile",0); |
| 600 | if( zLog && zLog[0] && (backofficeFILE = fossil_fopen(zLog,"a"))!=0 ){ |
| 601 | int i; |
| 602 | char *zName = db_get("project-name",""); |
| 603 | #if !defined(_WIN32) |
| 604 | gettimeofday(&sStart, 0); |
| 605 | signal(SIGSEGV, backoffice_signal_handler); |
| 606 | signal(SIGABRT, backoffice_signal_handler); |
| 607 | signal(SIGFPE, backoffice_signal_handler); |
| 608 | signal(SIGILL, backoffice_signal_handler); |
| 609 | #endif |
| 610 | /* Convert all spaces in the "project-name" into dashes */ |
| 611 | for(i=0; zName[i]; i++){ if( zName[i]==' ' ) zName[i] = '-'; } |
| 612 | blob_init(&log, 0, 0); |
| 613 | backofficeBlob = &log; |
| 614 | blob_appendf(&log, "%s %s", db_text(0, "SELECT datetime('now')"), zName); |
| 615 | } |
| 616 | |
| @@ -620,16 +630,19 @@ | |
| 620 | nThis = smtp_cleanup(); |
| 621 | if( nThis ){ backoffice_log("%d SMTPs", nThis); nTotal += nThis; } |
| 622 | |
| 623 | /* Close the log */ |
| 624 | if( backofficeFILE ){ |
| 625 | if( nTotal==0 ) backoffice_log("no-op"); |
| 626 | #if !defined(_WIN32) |
| 627 | gettimeofday(&sEnd,0); |
| 628 | backoffice_log("elapse-time %d us", tvms(&sEnd) - tvms(&sStart)); |
| 629 | #endif |
| 630 | fprintf(backofficeFILE, "%s\n", blob_str(backofficeBlob)); |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | /* |
| 635 | ** COMMAND: backoffice* |
| @@ -647,11 +660,11 @@ | |
| 647 | ** If only a single repository is named and --poll is omitted, the the |
| 648 | ** backoffice work is done in-process. But if there are multiple respositories |
| 649 | ** or if --poll is used, a separate sub-process is started for each poll of |
| 650 | ** each repository. |
| 651 | ** |
| 652 | ** OPTIONS: |
| 653 | ** |
| 654 | ** --debug Show what this command is doing. |
| 655 | ** |
| 656 | ** --logfile FILE Append a log of backoffice actions onto FILE. |
| 657 | ** |
| @@ -661,34 +674,40 @@ | |
| 661 | ** this feature. Default: 3600 (once per hour). |
| 662 | ** |
| 663 | ** --nodelay Do not queue up or wait for a backoffice job |
| 664 | ** to complete. If no work is available or if |
| 665 | ** backoffice has run recently, return immediately. |
| 666 | ** The --nodelay option is implied if more than |
| 667 | ** one repository is listed on the command-line. |
| 668 | ** |
| 669 | ** --poll N Repeat backoffice calls for repositories that |
| 670 | ** change in appoximately N-second intervals. |
| 671 | ** N less than 1 turns polling off (the default). |
| 672 | ** Recommended polling interval: 60 seconds. |
| 673 | ** |
| 674 | ** --trace Enable debugging output on stderr |
| 675 | */ |
| 676 | void backoffice_command(void){ |
| 677 | int nPoll; |
| 678 | int nMin; |
| 679 | const char *zPoll; |
| 680 | int bDebug = 0; |
| 681 | unsigned int nCmd = 0; |
| 682 | if( find_option("trace",0,0)!=0 ) g.fAnyTrace = 1; |
| 683 | if( find_option("nodelay",0,0)!=0 ) backofficeNoDelay = 1; |
| 684 | backofficeLogfile = find_option("logfile",0,1); |
| 685 | zPoll = find_option("poll",0,1); |
| 686 | nPoll = zPoll ? atoi(zPoll) : 0; |
| 687 | zPoll = find_option("min",0,1); |
| 688 | nMin = zPoll ? atoi(zPoll) : 3600; |
| 689 | bDebug = find_option("debug",0,0)!=0; |
| 690 | |
| 691 | /* Silently consume the -R or --repository flag, leaving behind its |
| 692 | ** argument. This is for legacy compatibility. Older versions of the |
| 693 | ** backoffice command only ran on a single repository that was specified |
| 694 | ** using the -R option. */ |
| @@ -721,10 +740,20 @@ | |
| 721 | blob_append_escaped_arg(&cmd, g.nameOfExe); |
| 722 | blob_append(&cmd, " backoffice --nodelay", -1); |
| 723 | if( g.fAnyTrace ){ |
| 724 | blob_append(&cmd, " --trace", -1); |
| 725 | } |
| 726 | blob_append_escaped_arg(&cmd, g.argv[i]); |
| 727 | nCmd++; |
| 728 | if( bDebug ){ |
| 729 | fossil_print("COMMAND[%u]: %s\n", nCmd, blob_str(&cmd)); |
| 730 | } |
| @@ -748,10 +777,13 @@ | |
| 748 | g.zRepositoryOption = g.argv[2]; |
| 749 | g.argc--; |
| 750 | } |
| 751 | db_find_and_open_repository(0,0); |
| 752 | if( bDebug ){ |
| 753 | backoffice_work(); |
| 754 | }else{ |
| 755 | backoffice_thread(); |
| 756 | } |
| 757 | } |
| 758 |
| --- src/backoffice.c | |
| +++ src/backoffice.c | |
| @@ -145,10 +145,15 @@ | |
| 145 | /* |
| 146 | ** Write backoffice log messages on this BLOB. to this connection: |
| 147 | */ |
| 148 | static Blob *backofficeBlob = 0; |
| 149 | |
| 150 | /* |
| 151 | ** Non-zero for extra logging detail. |
| 152 | */ |
| 153 | static int backofficeLogDetail = 0; |
| 154 | |
| 155 | /* End of state variables |
| 156 | ****************************************************************************/ |
| 157 | |
| 158 | /* |
| 159 | ** This function emits a diagnostic message related to the processing in |
| @@ -597,20 +602,25 @@ | |
| 602 | struct timeval sStart, sEnd; |
| 603 | #endif |
| 604 | if( zLog==0 ) zLog = db_get("backoffice-logfile",0); |
| 605 | if( zLog && zLog[0] && (backofficeFILE = fossil_fopen(zLog,"a"))!=0 ){ |
| 606 | int i; |
| 607 | char *zName = db_get("project-name",0); |
| 608 | #if !defined(_WIN32) |
| 609 | gettimeofday(&sStart, 0); |
| 610 | signal(SIGSEGV, backoffice_signal_handler); |
| 611 | signal(SIGABRT, backoffice_signal_handler); |
| 612 | signal(SIGFPE, backoffice_signal_handler); |
| 613 | signal(SIGILL, backoffice_signal_handler); |
| 614 | #endif |
| 615 | if( zName==0 ){ |
| 616 | zName = (char*)file_tail(g.zRepositoryName); |
| 617 | if( zName==0 ) zName = "(unnamed)"; |
| 618 | }else{ |
| 619 | /* Convert all spaces in the "project-name" into dashes */ |
| 620 | for(i=0; zName[i]; i++){ if( zName[i]==' ' ) zName[i] = '-'; } |
| 621 | } |
| 622 | blob_init(&log, 0, 0); |
| 623 | backofficeBlob = &log; |
| 624 | blob_appendf(&log, "%s %s", db_text(0, "SELECT datetime('now')"), zName); |
| 625 | } |
| 626 | |
| @@ -620,16 +630,19 @@ | |
| 630 | nThis = smtp_cleanup(); |
| 631 | if( nThis ){ backoffice_log("%d SMTPs", nThis); nTotal += nThis; } |
| 632 | |
| 633 | /* Close the log */ |
| 634 | if( backofficeFILE ){ |
| 635 | if( nTotal || backofficeLogDetail ){ |
| 636 | if( nTotal==0 ) backoffice_log("no-op"); |
| 637 | #if !defined(_WIN32) |
| 638 | gettimeofday(&sEnd,0); |
| 639 | backoffice_log("elapse-time %d us", tvms(&sEnd) - tvms(&sStart)); |
| 640 | #endif |
| 641 | fprintf(backofficeFILE, "%s\n", blob_str(backofficeBlob)); |
| 642 | } |
| 643 | fclose(backofficeFILE); |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | /* |
| 648 | ** COMMAND: backoffice* |
| @@ -647,11 +660,11 @@ | |
| 660 | ** If only a single repository is named and --poll is omitted, the the |
| 661 | ** backoffice work is done in-process. But if there are multiple respositories |
| 662 | ** or if --poll is used, a separate sub-process is started for each poll of |
| 663 | ** each repository. |
| 664 | ** |
| 665 | ** Standard options: |
| 666 | ** |
| 667 | ** --debug Show what this command is doing. |
| 668 | ** |
| 669 | ** --logfile FILE Append a log of backoffice actions onto FILE. |
| 670 | ** |
| @@ -661,34 +674,40 @@ | |
| 674 | ** this feature. Default: 3600 (once per hour). |
| 675 | ** |
| 676 | ** --nodelay Do not queue up or wait for a backoffice job |
| 677 | ** to complete. If no work is available or if |
| 678 | ** backoffice has run recently, return immediately. |
| 679 | ** |
| 680 | ** --poll N Repeat backoffice calls for repositories that |
| 681 | ** change in appoximately N-second intervals. |
| 682 | ** N less than 1 turns polling off (the default). |
| 683 | ** Recommended polling interval: 60 seconds. |
| 684 | ** |
| 685 | ** --trace Enable debugging output on stderr |
| 686 | ** |
| 687 | ** Options intended for internal use only which may change or be |
| 688 | ** discontinued in a future release: |
| 689 | ** |
| 690 | ** --nolease Always run backoffice, even if there is a lease |
| 691 | ** conflict. This option implies --nodelay. |
| 692 | */ |
| 693 | void backoffice_command(void){ |
| 694 | int nPoll; |
| 695 | int nMin; |
| 696 | const char *zPoll; |
| 697 | int bDebug = 0; |
| 698 | int bNoLease = 0; |
| 699 | unsigned int nCmd = 0; |
| 700 | if( find_option("trace",0,0)!=0 ) g.fAnyTrace = 1; |
| 701 | if( find_option("nodelay",0,0)!=0 ) backofficeNoDelay = 1; |
| 702 | backofficeLogfile = find_option("logfile",0,1); |
| 703 | zPoll = find_option("poll",0,1); |
| 704 | nPoll = zPoll ? atoi(zPoll) : 0; |
| 705 | zPoll = find_option("min",0,1); |
| 706 | nMin = zPoll ? atoi(zPoll) : 3600; |
| 707 | bDebug = find_option("debug",0,0)!=0; |
| 708 | bNoLease = find_option("nolease",0,0)!=0; |
| 709 | |
| 710 | /* Silently consume the -R or --repository flag, leaving behind its |
| 711 | ** argument. This is for legacy compatibility. Older versions of the |
| 712 | ** backoffice command only ran on a single repository that was specified |
| 713 | ** using the -R option. */ |
| @@ -721,10 +740,20 @@ | |
| 740 | blob_append_escaped_arg(&cmd, g.nameOfExe); |
| 741 | blob_append(&cmd, " backoffice --nodelay", -1); |
| 742 | if( g.fAnyTrace ){ |
| 743 | blob_append(&cmd, " --trace", -1); |
| 744 | } |
| 745 | if( bDebug ){ |
| 746 | blob_append(&cmd, " --debug", -1); |
| 747 | } |
| 748 | if( nPoll>0 ){ |
| 749 | blob_append(&cmd, " --nolease", -1); |
| 750 | } |
| 751 | if( backofficeLogfile ){ |
| 752 | blob_append(&cmd, " --logfile", -1); |
| 753 | blob_append_escaped_arg(&cmd, backofficeLogfile); |
| 754 | } |
| 755 | blob_append_escaped_arg(&cmd, g.argv[i]); |
| 756 | nCmd++; |
| 757 | if( bDebug ){ |
| 758 | fossil_print("COMMAND[%u]: %s\n", nCmd, blob_str(&cmd)); |
| 759 | } |
| @@ -748,10 +777,13 @@ | |
| 777 | g.zRepositoryOption = g.argv[2]; |
| 778 | g.argc--; |
| 779 | } |
| 780 | db_find_and_open_repository(0,0); |
| 781 | if( bDebug ){ |
| 782 | backofficeLogDetail = 1; |
| 783 | } |
| 784 | if( bNoLease ){ |
| 785 | backoffice_work(); |
| 786 | }else{ |
| 787 | backoffice_thread(); |
| 788 | } |
| 789 | } |
| 790 |