Fossil SCM
Enhancements to the "backoffice" command: Added the --nodelay option and added the ability to specify multiple repositories.
Commit
96fc48487662e52890652002db31b0a6a92b057c9c07c359e317f7d9a61b43c8
Parent
3790dbbd36ce6c4…
1 file changed
+56
-5
+56
-5
| --- src/backoffice.c | ||
| +++ src/backoffice.c | ||
| @@ -454,10 +454,12 @@ | ||
| 454 | 454 | ){ |
| 455 | 455 | /* Another backoffice process is already queued up to run. This |
| 456 | 456 | ** process does not need to do any backoffice work and can stop |
| 457 | 457 | ** immediately. */ |
| 458 | 458 | db_end_transaction(0); |
| 459 | + backofficeTrace("/***** Backoffice Processing Not Needed In %d *****/\n", | |
| 460 | + GETPID()); | |
| 459 | 461 | break; |
| 460 | 462 | } |
| 461 | 463 | if( x.tmCurrent<tmNow && backofficeProcessDone(x.idCurrent) ){ |
| 462 | 464 | /* This process can start doing backoffice work immediately */ |
| 463 | 465 | x.idCurrent = idSelf; |
| @@ -474,10 +476,13 @@ | ||
| 474 | 476 | if( backofficeNoDelay || db_get_boolean("backoffice-nodelay",0) ){ |
| 475 | 477 | /* If the no-delay flag is set, exit immediately rather than queuing |
| 476 | 478 | ** up. Assume that some future request will come along and handle any |
| 477 | 479 | ** necessary backoffice work. */ |
| 478 | 480 | db_end_transaction(0); |
| 481 | + backofficeTrace( | |
| 482 | + "/***** Backoffice No-Delay Exit For %d *****/\n", | |
| 483 | + GETPID()); | |
| 479 | 484 | break; |
| 480 | 485 | } |
| 481 | 486 | /* This process needs to queue up and wait for the current lease |
| 482 | 487 | ** to expire before continuing. */ |
| 483 | 488 | x.idNext = idSelf; |
| @@ -535,20 +540,66 @@ | ||
| 535 | 540 | } |
| 536 | 541 | |
| 537 | 542 | /* |
| 538 | 543 | ** COMMAND: backoffice* |
| 539 | 544 | ** |
| 540 | -** Usage: backoffice [-R repository] | |
| 545 | +** Usage: backoffice [OPTIONS...] [REPOSITORIES...] | |
| 546 | +** | |
| 547 | +** Run backoffice processing on the repositories listed. If no | |
| 548 | +** repository is specified, run it on the repository of the local checkout. | |
| 549 | +** | |
| 550 | +** This might be done by a cron job or similar to make sure backoffice | |
| 551 | +** processing happens periodically. | |
| 552 | +** | |
| 553 | +** Options: | |
| 554 | +** | |
| 555 | +** --nodelay Do not queue up or wait for a backoffice job | |
| 556 | +** to complete. If no work is available or if | |
| 557 | +** backoffice has run recently, return immediately. | |
| 558 | +** The --nodelay option is implied if more than | |
| 559 | +** one repository is listed on the command-line. | |
| 541 | 560 | ** |
| 542 | -** Run backoffice processing. This might be done by a cron job or | |
| 543 | -** similar to make sure backoffice processing happens periodically. | |
| 561 | +** --trace Enable debugging output on stderr | |
| 544 | 562 | */ |
| 545 | 563 | void backoffice_command(void){ |
| 546 | 564 | if( find_option("trace",0,0)!=0 ) g.fAnyTrace = 1; |
| 547 | - db_find_and_open_repository(0,0); | |
| 565 | + if( find_option("nodelay",0,0)!=0 ) backofficeNoDelay = 1; | |
| 566 | + | |
| 567 | + /* Silently consume the -R or --repository flag, leaving behind its | |
| 568 | + ** argument. This is for legacy compatibility. Older versions of the | |
| 569 | + ** backoffice command only ran on a single repository that was specified | |
| 570 | + ** using the -R option. */ | |
| 571 | + (void)find_option("repository","R",0); | |
| 572 | + | |
| 548 | 573 | verify_all_options(); |
| 549 | - backoffice_thread(); | |
| 574 | + if( g.argc>3 ){ | |
| 575 | + /* Multiple repositories named on the command-line. Run each in a | |
| 576 | + ** separate sub-process */ | |
| 577 | + int i; | |
| 578 | + for(i=2; i<g.argc; i++){ | |
| 579 | + Blob cmd; | |
| 580 | + blob_init(&cmd, 0, 0); | |
| 581 | + blob_append_escaped_arg(&cmd, g.nameOfExe); | |
| 582 | + blob_append(&cmd, " backoffice --nodelay", -1); | |
| 583 | + if( g.fAnyTrace ){ | |
| 584 | + blob_append(&cmd, " --trace", -1); | |
| 585 | + } | |
| 586 | + blob_append_escaped_arg(&cmd, g.argv[i]); | |
| 587 | + if( g.fAnyTrace ){ | |
| 588 | + fossil_print("-- %s\n", blob_str(&cmd)); | |
| 589 | + } | |
| 590 | + fossil_system(blob_str(&cmd)); | |
| 591 | + blob_reset(&cmd); | |
| 592 | + } | |
| 593 | + }else{ | |
| 594 | + if( g.argc==3 ){ | |
| 595 | + g.zRepositoryOption = g.argv[2]; | |
| 596 | + g.argc--; | |
| 597 | + } | |
| 598 | + db_find_and_open_repository(0,0); | |
| 599 | + backoffice_thread(); | |
| 600 | + } | |
| 550 | 601 | } |
| 551 | 602 | |
| 552 | 603 | /* |
| 553 | 604 | ** This is the main interface to backoffice from the rest of the system. |
| 554 | 605 | ** This routine launches either backoffice_thread() directly or as a |
| 555 | 606 |
| --- src/backoffice.c | |
| +++ src/backoffice.c | |
| @@ -454,10 +454,12 @@ | |
| 454 | ){ |
| 455 | /* Another backoffice process is already queued up to run. This |
| 456 | ** process does not need to do any backoffice work and can stop |
| 457 | ** immediately. */ |
| 458 | db_end_transaction(0); |
| 459 | break; |
| 460 | } |
| 461 | if( x.tmCurrent<tmNow && backofficeProcessDone(x.idCurrent) ){ |
| 462 | /* This process can start doing backoffice work immediately */ |
| 463 | x.idCurrent = idSelf; |
| @@ -474,10 +476,13 @@ | |
| 474 | if( backofficeNoDelay || db_get_boolean("backoffice-nodelay",0) ){ |
| 475 | /* If the no-delay flag is set, exit immediately rather than queuing |
| 476 | ** up. Assume that some future request will come along and handle any |
| 477 | ** necessary backoffice work. */ |
| 478 | db_end_transaction(0); |
| 479 | break; |
| 480 | } |
| 481 | /* This process needs to queue up and wait for the current lease |
| 482 | ** to expire before continuing. */ |
| 483 | x.idNext = idSelf; |
| @@ -535,20 +540,66 @@ | |
| 535 | } |
| 536 | |
| 537 | /* |
| 538 | ** COMMAND: backoffice* |
| 539 | ** |
| 540 | ** Usage: backoffice [-R repository] |
| 541 | ** |
| 542 | ** Run backoffice processing. This might be done by a cron job or |
| 543 | ** similar to make sure backoffice processing happens periodically. |
| 544 | */ |
| 545 | void backoffice_command(void){ |
| 546 | if( find_option("trace",0,0)!=0 ) g.fAnyTrace = 1; |
| 547 | db_find_and_open_repository(0,0); |
| 548 | verify_all_options(); |
| 549 | backoffice_thread(); |
| 550 | } |
| 551 | |
| 552 | /* |
| 553 | ** This is the main interface to backoffice from the rest of the system. |
| 554 | ** This routine launches either backoffice_thread() directly or as a |
| 555 |
| --- src/backoffice.c | |
| +++ src/backoffice.c | |
| @@ -454,10 +454,12 @@ | |
| 454 | ){ |
| 455 | /* Another backoffice process is already queued up to run. This |
| 456 | ** process does not need to do any backoffice work and can stop |
| 457 | ** immediately. */ |
| 458 | db_end_transaction(0); |
| 459 | backofficeTrace("/***** Backoffice Processing Not Needed In %d *****/\n", |
| 460 | GETPID()); |
| 461 | break; |
| 462 | } |
| 463 | if( x.tmCurrent<tmNow && backofficeProcessDone(x.idCurrent) ){ |
| 464 | /* This process can start doing backoffice work immediately */ |
| 465 | x.idCurrent = idSelf; |
| @@ -474,10 +476,13 @@ | |
| 476 | if( backofficeNoDelay || db_get_boolean("backoffice-nodelay",0) ){ |
| 477 | /* If the no-delay flag is set, exit immediately rather than queuing |
| 478 | ** up. Assume that some future request will come along and handle any |
| 479 | ** necessary backoffice work. */ |
| 480 | db_end_transaction(0); |
| 481 | backofficeTrace( |
| 482 | "/***** Backoffice No-Delay Exit For %d *****/\n", |
| 483 | GETPID()); |
| 484 | break; |
| 485 | } |
| 486 | /* This process needs to queue up and wait for the current lease |
| 487 | ** to expire before continuing. */ |
| 488 | x.idNext = idSelf; |
| @@ -535,20 +540,66 @@ | |
| 540 | } |
| 541 | |
| 542 | /* |
| 543 | ** COMMAND: backoffice* |
| 544 | ** |
| 545 | ** Usage: backoffice [OPTIONS...] [REPOSITORIES...] |
| 546 | ** |
| 547 | ** Run backoffice processing on the repositories listed. If no |
| 548 | ** repository is specified, run it on the repository of the local checkout. |
| 549 | ** |
| 550 | ** This might be done by a cron job or similar to make sure backoffice |
| 551 | ** processing happens periodically. |
| 552 | ** |
| 553 | ** Options: |
| 554 | ** |
| 555 | ** --nodelay Do not queue up or wait for a backoffice job |
| 556 | ** to complete. If no work is available or if |
| 557 | ** backoffice has run recently, return immediately. |
| 558 | ** The --nodelay option is implied if more than |
| 559 | ** one repository is listed on the command-line. |
| 560 | ** |
| 561 | ** --trace Enable debugging output on stderr |
| 562 | */ |
| 563 | void backoffice_command(void){ |
| 564 | if( find_option("trace",0,0)!=0 ) g.fAnyTrace = 1; |
| 565 | if( find_option("nodelay",0,0)!=0 ) backofficeNoDelay = 1; |
| 566 | |
| 567 | /* Silently consume the -R or --repository flag, leaving behind its |
| 568 | ** argument. This is for legacy compatibility. Older versions of the |
| 569 | ** backoffice command only ran on a single repository that was specified |
| 570 | ** using the -R option. */ |
| 571 | (void)find_option("repository","R",0); |
| 572 | |
| 573 | verify_all_options(); |
| 574 | if( g.argc>3 ){ |
| 575 | /* Multiple repositories named on the command-line. Run each in a |
| 576 | ** separate sub-process */ |
| 577 | int i; |
| 578 | for(i=2; i<g.argc; i++){ |
| 579 | Blob cmd; |
| 580 | blob_init(&cmd, 0, 0); |
| 581 | blob_append_escaped_arg(&cmd, g.nameOfExe); |
| 582 | blob_append(&cmd, " backoffice --nodelay", -1); |
| 583 | if( g.fAnyTrace ){ |
| 584 | blob_append(&cmd, " --trace", -1); |
| 585 | } |
| 586 | blob_append_escaped_arg(&cmd, g.argv[i]); |
| 587 | if( g.fAnyTrace ){ |
| 588 | fossil_print("-- %s\n", blob_str(&cmd)); |
| 589 | } |
| 590 | fossil_system(blob_str(&cmd)); |
| 591 | blob_reset(&cmd); |
| 592 | } |
| 593 | }else{ |
| 594 | if( g.argc==3 ){ |
| 595 | g.zRepositoryOption = g.argv[2]; |
| 596 | g.argc--; |
| 597 | } |
| 598 | db_find_and_open_repository(0,0); |
| 599 | backoffice_thread(); |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | /* |
| 604 | ** This is the main interface to backoffice from the rest of the system. |
| 605 | ** This routine launches either backoffice_thread() directly or as a |
| 606 |