Fossil SCM

Improvements to backoffice polling using the "fossil backoffice" command.

drh 2020-07-02 01:56 trunk
Commit 75b76efbba2a5c9b7981f3ae579ab295885cd50a357d12cb383647ac23017d27
1 file changed +42 -10
+42 -10
--- src/backoffice.c
+++ src/backoffice.c
@@ -145,10 +145,15 @@
145145
/*
146146
** Write backoffice log messages on this BLOB. to this connection:
147147
*/
148148
static Blob *backofficeBlob = 0;
149149
150
+/*
151
+** Non-zero for extra logging detail.
152
+*/
153
+static int backofficeLogDetail = 0;
154
+
150155
/* End of state variables
151156
****************************************************************************/
152157
153158
/*
154159
** This function emits a diagnostic message related to the processing in
@@ -597,20 +602,25 @@
597602
struct timeval sStart, sEnd;
598603
#endif
599604
if( zLog==0 ) zLog = db_get("backoffice-logfile",0);
600605
if( zLog && zLog[0] && (backofficeFILE = fossil_fopen(zLog,"a"))!=0 ){
601606
int i;
602
- char *zName = db_get("project-name","");
607
+ char *zName = db_get("project-name",0);
603608
#if !defined(_WIN32)
604609
gettimeofday(&sStart, 0);
605610
signal(SIGSEGV, backoffice_signal_handler);
606611
signal(SIGABRT, backoffice_signal_handler);
607612
signal(SIGFPE, backoffice_signal_handler);
608613
signal(SIGILL, backoffice_signal_handler);
609614
#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
+ }
612622
blob_init(&log, 0, 0);
613623
backofficeBlob = &log;
614624
blob_appendf(&log, "%s %s", db_text(0, "SELECT datetime('now')"), zName);
615625
}
616626
@@ -620,16 +630,19 @@
620630
nThis = smtp_cleanup();
621631
if( nThis ){ backoffice_log("%d SMTPs", nThis); nTotal += nThis; }
622632
623633
/* Close the log */
624634
if( backofficeFILE ){
625
- if( nTotal==0 ) backoffice_log("no-op");
635
+ if( nTotal || backofficeLogDetail ){
636
+ if( nTotal==0 ) backoffice_log("no-op");
626637
#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));
629640
#endif
630
- fprintf(backofficeFILE, "%s\n", blob_str(backofficeBlob));
641
+ fprintf(backofficeFILE, "%s\n", blob_str(backofficeBlob));
642
+ }
643
+ fclose(backofficeFILE);
631644
}
632645
}
633646
634647
/*
635648
** COMMAND: backoffice*
@@ -647,11 +660,11 @@
647660
** If only a single repository is named and --poll is omitted, the the
648661
** backoffice work is done in-process. But if there are multiple respositories
649662
** or if --poll is used, a separate sub-process is started for each poll of
650663
** each repository.
651664
**
652
-** OPTIONS:
665
+** Standard options:
653666
**
654667
** --debug Show what this command is doing.
655668
**
656669
** --logfile FILE Append a log of backoffice actions onto FILE.
657670
**
@@ -661,34 +674,40 @@
661674
** this feature. Default: 3600 (once per hour).
662675
**
663676
** --nodelay Do not queue up or wait for a backoffice job
664677
** to complete. If no work is available or if
665678
** backoffice has run recently, return immediately.
666
-** The --nodelay option is implied if more than
667
-** one repository is listed on the command-line.
668679
**
669680
** --poll N Repeat backoffice calls for repositories that
670681
** change in appoximately N-second intervals.
671682
** N less than 1 turns polling off (the default).
672683
** Recommended polling interval: 60 seconds.
673684
**
674685
** --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.
675692
*/
676693
void backoffice_command(void){
677694
int nPoll;
678695
int nMin;
679696
const char *zPoll;
680697
int bDebug = 0;
698
+ int bNoLease = 0;
681699
unsigned int nCmd = 0;
682700
if( find_option("trace",0,0)!=0 ) g.fAnyTrace = 1;
683701
if( find_option("nodelay",0,0)!=0 ) backofficeNoDelay = 1;
684702
backofficeLogfile = find_option("logfile",0,1);
685703
zPoll = find_option("poll",0,1);
686704
nPoll = zPoll ? atoi(zPoll) : 0;
687705
zPoll = find_option("min",0,1);
688706
nMin = zPoll ? atoi(zPoll) : 3600;
689707
bDebug = find_option("debug",0,0)!=0;
708
+ bNoLease = find_option("nolease",0,0)!=0;
690709
691710
/* Silently consume the -R or --repository flag, leaving behind its
692711
** argument. This is for legacy compatibility. Older versions of the
693712
** backoffice command only ran on a single repository that was specified
694713
** using the -R option. */
@@ -721,10 +740,20 @@
721740
blob_append_escaped_arg(&cmd, g.nameOfExe);
722741
blob_append(&cmd, " backoffice --nodelay", -1);
723742
if( g.fAnyTrace ){
724743
blob_append(&cmd, " --trace", -1);
725744
}
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
+ }
726755
blob_append_escaped_arg(&cmd, g.argv[i]);
727756
nCmd++;
728757
if( bDebug ){
729758
fossil_print("COMMAND[%u]: %s\n", nCmd, blob_str(&cmd));
730759
}
@@ -748,10 +777,13 @@
748777
g.zRepositoryOption = g.argv[2];
749778
g.argc--;
750779
}
751780
db_find_and_open_repository(0,0);
752781
if( bDebug ){
782
+ backofficeLogDetail = 1;
783
+ }
784
+ if( bNoLease ){
753785
backoffice_work();
754786
}else{
755787
backoffice_thread();
756788
}
757789
}
758790
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button