| 1 |
#!/usr/bin/env python3 |
| 2 |
"""Lock a workflow's database file.""" |
| 3 |
|
| 4 |
from fcntl import lockf, LOCK_SH |
| 5 |
import os |
| 6 |
import time |
| 7 |
from subprocess import call |
| 8 |
|
| 9 |
def main(): |
| 10 |
handle = open( |
| 11 |
os.path.join(os.getenv("CYLC_WORKFLOW_RUN_DIR"), "log", "db")) |
| 12 |
lockf(handle, LOCK_SH) |
| 13 |
call([ |
| 14 |
"cylc", "task-message", "I have locked the public database file"]) |
| 15 |
workflow_log_dir = os.getenv("CYLC_WORKFLOW_LOG_DIR") |
| 16 |
while True: |
| 17 |
for line in open(os.path.join(workflow_log_dir, "log")): |
| 18 |
if "db: recovered from" in line: |
| 19 |
return |
| 20 |
time.sleep(1) |
| 21 |
|
| 22 |
if __name__ == "__main__": |
| 23 |
main() |