-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from open-contracting/cron
New command check-collections
- Loading branch information
Showing
4 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Command line tool - check-collections option | ||
=========================================== | ||
|
||
This command checks all data so far in all collections. | ||
|
||
It can be run multiple times, and data already checked will not be rechecked. | ||
|
||
You should only run one of these at once, as if two are run at once they may try and do the same work. | ||
|
||
.. code-block:: shell-session | ||
python ocdskingfisher-process-cli check-collections | ||
Running from cron | ||
----------------- | ||
|
||
You can also pass a maximum number of seconds that the process should run for. | ||
|
||
.. code-block:: shell-session | ||
python ocdskingfisher-process-cli check-collections --runforseconds 60 | ||
Soon after that number of seconds has passed, the command will exit. | ||
(The command will finish the check it's currently doing before stopping, so it may run slightly longer than specified. Allow a minute extra to be safe.) | ||
|
||
You can use this option with a cron entry; set a cron entry for this command to run every hour and pass runforseconds as 3540 (60 seconds/minute * 59 minutes). | ||
|
||
Then when new data appears in the system, there is no need for someone to run :doc:`cli-check-collection` by hand - the process run by cron will pick up the new data itself eventually. | ||
|
||
The runforseconds option will make sure that only one of these cron processes runs at once. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import ocdskingfisherprocess.database | ||
import ocdskingfisherprocess.cli.commands.base | ||
from ocdskingfisherprocess.checks import Checks | ||
import datetime | ||
from threading import Timer | ||
import os | ||
|
||
|
||
class CheckCollectionsCLICommand(ocdskingfisherprocess.cli.commands.base.CLICommand): | ||
command = 'check-collections' | ||
|
||
def configure_subparser(self, subparser): | ||
subparser.add_argument("--runforseconds", | ||
help="Run for this many seconds only.") | ||
|
||
def run_command(self, args): | ||
run_until_timestamp = None | ||
run_for_seconds = int(args.runforseconds) if args.runforseconds else 0 | ||
if run_for_seconds > 0: | ||
run_until_timestamp = datetime.datetime.utcnow().timestamp() + run_for_seconds | ||
|
||
# This is a safeguard - the process should stop itself but this will kill it if it does not. | ||
def exitfunc(): | ||
os._exit(0) | ||
|
||
Timer(run_for_seconds + 60, exitfunc).start() | ||
|
||
for collection in self.database.get_all_collections(): | ||
checks = Checks(self.database, collection, run_until_timestamp=run_until_timestamp) | ||
checks.process_all_files() |