Fossil SCM

Update the backoffice poller so that it invokes each backoffice at least once every hour - configurable using the --min command-line option.

drh 2020-06-23 12:52 trunk
Commit e1d8cea28ae395235bc3267446c89fc5caefdd6fc431f3810159df57c4cbf892
1 file changed +23 -2
+23 -2
--- src/backoffice.c
+++ src/backoffice.c
@@ -555,31 +555,40 @@
555555
**
556556
** OPTIONS:
557557
**
558558
** --debug Show what this command is doing.
559559
**
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
+**
560565
** --nodelay Do not queue up or wait for a backoffice job
561566
** to complete. If no work is available or if
562567
** backoffice has run recently, return immediately.
563568
** The --nodelay option is implied if more than
564569
** one repository is listed on the command-line.
565570
**
566571
** --poll N Repeat backoffice calls for repositories that
567572
** change in appoximately N-second intervals.
568573
** N less than 1 turns polling off (the default).
574
+** Recommended polling interval: 60 seconds.
569575
**
570576
** --trace Enable debugging output on stderr
571577
*/
572578
void backoffice_command(void){
573579
int nPoll;
580
+ int nMin;
574581
const char *zPoll;
575582
int bDebug = 0;
576583
unsigned int nCmd = 0;
577584
if( find_option("trace",0,0)!=0 ) g.fAnyTrace = 1;
578585
if( find_option("nodelay",0,0)!=0 ) backofficeNoDelay = 1;
579586
zPoll = find_option("poll",0,1);
580587
nPoll = zPoll ? atoi(zPoll) : 0;
588
+ zPoll = find_option("min",0,1);
589
+ nMin = zPoll ? atoi(zPoll) : 3600;
581590
bDebug = find_option("debug",0,0)!=0;
582591
583592
/* Silently consume the -R or --repository flag, leaving behind its
584593
** argument. This is for legacy compatibility. Older versions of the
585594
** backoffice command only ran on a single repository that was specified
@@ -592,16 +601,25 @@
592601
** or we are polling. In either case, each backoffice should be run
593602
** using a separate sub-process */
594603
int i;
595604
time_t iNow = 0;
596605
time_t ix;
606
+ i64 *aLastRun = fossil_malloc( sizeof(i64)*g.argc );
607
+ memset(aLastRun, 0, sizeof(i64)*g.argc );
597608
while( 1 /* exit via "break;" */){
598609
time_t iNext = time(0);
599610
for(i=2; i<g.argc; i++){
600611
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
+ }
603621
blob_init(&cmd, 0, 0);
604622
blob_append_escaped_arg(&cmd, g.nameOfExe);
605623
blob_append(&cmd, " backoffice --nodelay", -1);
606624
if( g.fAnyTrace ){
607625
blob_append(&cmd, " --trace", -1);
@@ -610,10 +628,11 @@
610628
nCmd++;
611629
if( bDebug ){
612630
fossil_print("COMMAND[%u]: %s\n", nCmd, blob_str(&cmd));
613631
}
614632
fossil_system(blob_str(&cmd));
633
+ aLastRun[i] = iNext;
615634
blob_reset(&cmd);
616635
}
617636
if( nPoll<1 ) break;
618637
iNow = iNext;
619638
ix = time(0);
@@ -622,10 +641,12 @@
622641
if( bDebug )fossil_print("SLEEP: %lld\n", nMS);
623642
sqlite3_sleep((int)nMS);
624643
}
625644
}
626645
}else{
646
+ /* Not polling and only one repository named. Backoffice is run
647
+ ** once by this process, which then exits */
627648
if( g.argc==3 ){
628649
g.zRepositoryOption = g.argv[2];
629650
g.argc--;
630651
}
631652
db_find_and_open_repository(0,0);
632653
--- 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

Keyboard Shortcuts

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