current
Last change
on this file was
715671f,
checked in by Borja Lopez <borja@…>, 5 years ago
|
(#77) Bulk workouts upload:
- Added methods to extract files from compressed bulk files, then load
workouts from those files.
- Added a task to process/load workouts from "not loaded" bulk files
- Added full tests coverage
|
-
Property mode set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[715671f] | 1 | import fcntl |
---|
| 2 | import logging |
---|
| 3 | |
---|
| 4 | log = logging.getLogger(__name__) |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | def process_compressed_files(env): |
---|
| 8 | """ |
---|
| 9 | Go over any pending-to-be-processed compressed files for bulk-upload |
---|
| 10 | workouts from those files. |
---|
| 11 | """ |
---|
| 12 | |
---|
| 13 | settings = env['registry'].settings |
---|
| 14 | lock_filename = settings.get('workouts.bulk_loading_lock') |
---|
| 15 | lock_file = open(lock_filename, 'w') |
---|
| 16 | try: |
---|
| 17 | fcntl.lockf(lock_file, fcntl.LOCK_EX | fcntl.LOCK_NB) |
---|
| 18 | except IOError: |
---|
| 19 | # Can't lock, probably another process is running, report to logging |
---|
| 20 | # and exit |
---|
| 21 | log.warning('Could not run the workout bulk load task, ' |
---|
| 22 | 'could not acquire lock (maybe another process is ' |
---|
| 23 | 'running?)') |
---|
| 24 | return False |
---|
| 25 | |
---|
| 26 | request = env['request'] |
---|
| 27 | root = env['root'] |
---|
| 28 | workouts_loaded = False |
---|
| 29 | tmp_path = settings.get('workouts.bulk_tmp_path') |
---|
| 30 | |
---|
| 31 | for bulk_file in root['_bulk_files'].values(): |
---|
| 32 | if not bulk_file.loaded: |
---|
| 33 | bulk_file.load(root, tmp_path) |
---|
| 34 | workouts_loaded = True |
---|
| 35 | |
---|
| 36 | if workouts_loaded: |
---|
| 37 | request.tm.commit() |
---|
| 38 | |
---|
| 39 | return workouts_loaded |
---|
Note: See
TracBrowser
for help on using the repository browser.