Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4

- uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: uv sync --group dev

- name: Run tests
run: uv run pytest

ruff:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
permissions:
contents: read
pull-requests: write

steps:
- uses: actions/checkout@v4

- uses: benny123tw/action-ruff@v1.1.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-pr-review
filter_mode: diff_context
170 changes: 170 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
.python-version

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/

# VSCode
.vscode/

# Custom
tmpdev/

# setuptools-scm generated version file
src/sosci/__about__.py
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
repos:
- repo: https://github.com/pycqa/isort
rev: 6.0.1
hooks:
- id: isort

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.12.5
hooks:
- id: ruff

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-yaml
args: [--unsafe]
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-added-large-files
- id: check-toml
- id: check-merge-conflict
- id: debug-statements

# Replace commitsar with conventional commit checker
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v2.1.1
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
args: [] # default: [feat, fix, ci, chore, docs, style, refactor, perf, test, build, revert]
95 changes: 95 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# sosci

**S**imons **O**bservatory **S**oftware and **C**omputing **I**nfrastructure — a daemon that watches a local directory for file changes and automatically syncs them to one or more remote destinations using Globus.

## Features

- **Polling-based file watcher** — monitors a source directory for created, modified, and deleted files using watchdog's polling observer, compatible with any filesystem (including network mounts).
- **File stability detection** — waits for files to stop growing before triggering a transfer, avoiding partial uploads.
- **Multi-destination sync** — supports syncing to multiple Globus endpoints, each with its own authentication credentials.
- **Crash recovery via snapshots** — saves a `DirectorySnapshot` on shutdown. On restart, diffs the snapshot against the current filesystem to detect changes that occurred while the daemon was down.
- **Globus transfers** — uses the Globus SDK for reliable, encrypted, checksum-verified file transfers with automatic retry.
- **Rsync backend** — an alternative rsync-based transfer for local or SSH-accessible destinations.
- **Clean shutdown** — handles SIGTERM and SIGINT (Ctrl+C) to ensure all threads stop gracefully and snapshots are saved.

## Architecture

```
┌──────────────────────────────────────────────────────┐
│ Main Thread │
│ - Parses config │
│ - Wires watcher → transfer manager │
│ - Blocks until SIGTERM / SIGINT │
│ - Orchestrates clean shutdown │
└──────────────────────────────────────────────────────┘
│ │
▼ ▼
┌─────────────────────┐ ┌─────────────────────────┐
│ Watcher Thread │ │ Transfer Manager Thread │
│ (PollingObserver) │ │ │
│ │ │ - Receives file lists │
│ - Polls source dir │──▶│ via callback │
│ - Detects changes │ │ - Transfers to each │
│ - Checks stability │ │ Globus destination │
│ - Calls on_cycle_ │ │ - Handles deletes │
│ done callback │ │ │
└─────────────────────┘ └─────────────────────────┘
```

**Data flow:** Source directory → Watcher detects stable files → `on_cycle_done` callback → TransferManager syncs to all configured Globus destinations.

## Configuration

sosci is configured via a JSON file:

```json
{
"source": {
"path": "/data/experiment",
"endpoint": "source-endpoint-uuid",
"globus_root_path": "/root/path/on/source",
"base_path": "/data/experiment"
},
"destination": [
{
"path": "/data/backup",
"endpoint": "dest-endpoint-uuid",
"globus_root_path": "/root/path/on/dest",
"client_id": "globus-native-app-client-id",
"refresh_token_file": "~/.globus/tokens.json"
}
],
"poll_interval": 30,
"check_interval": 60,
"max_retries": 3,
"snapshot_path": "~/.sosci/sosci_snapshot.pkl"
}
```

| Field | Description |
|-------|-------------|
| `source` | Source directory and Globus endpoint configuration |
| `destination` | List of destination configurations, each with its own Globus credentials |
| `poll_interval` | Seconds between filesystem polls (default: 30) |
| `check_interval` | Seconds between modified-file checks during transfer (default: 60) |
| `max_retries` | Max checks for modified files before giving up (default: 3) |
| `snapshot_path` | Where to persist the directory snapshot for crash recovery (default: `~/.sosci/sosci_snapshot.pkl`) |

## Testing

Run the test suite with:

```bash
uv run pytest
```

## Usage

```bash
sosci --config config.json
```

Stop with Ctrl+C or `kill <pid>` — the daemon will save a snapshot and shut down cleanly.

[!NOTE]
README was edited with Claude AI.
Loading
Loading