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