Skip to content

Commit d98412a

Browse files
committed
feat: Add --run and --schedule execution modes with comprehensive Docker support
1 parent 19d8b89 commit d98412a

File tree

15 files changed

+1670
-52
lines changed

15 files changed

+1670
-52
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,4 @@ test_prod/
202202
config/config.toml
203203
# But keep the example file
204204
!config/config.example.toml
205+
export_trakt

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- **New execution modes**: `--run` flag for immediate one-time execution and `--schedule` flag for cron-based scheduling
13+
- Comprehensive cron schedule validation with helpful error messages and examples
14+
- Built-in scheduler with detailed logging and status reporting
15+
- Support for immediate execution mode for testing and CI/CD integration
16+
- Enhanced command-line interface with new scheduling options
1217
- Comprehensive test suite with unit and integration tests
1318
- Internationalization (i18n) support with English and French translations
1419
- GitHub Actions CI/CD pipeline for automated testing
1520
- Automated release workflow for cross-platform binary generation
1621
- New issue templates for bug reports, feature requests, and beta feedback
1722
- Enhanced documentation including contributing guide, installation instructions, and configuration guide
23+
- Detailed scheduling examples and best practices documentation
24+
25+
### Changed
26+
27+
- Improved command-line argument handling with support for multiple execution modes
28+
- Enhanced logging with scheduler-specific messages and status updates
29+
- Better error handling for invalid cron expressions with user-friendly feedback
1830

1931
## [2.0.0] - TBD
2032

DOCKER_CHANGES.md

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# Docker Compose Changes - New Scheduling Features
2+
3+
This document summarizes the changes made to the Docker Compose configuration to support the new `--run` and `--schedule` functionality.
4+
5+
## Overview of Changes
6+
7+
The Docker Compose configuration has been significantly enhanced to support three execution modes:
8+
9+
1. **Immediate Execution (`--run`)**: Execute once and exit
10+
2. **Scheduled Execution (`--schedule`)**: Run on a cron schedule
11+
3. **Legacy Mode**: Traditional command-based approach (for backward compatibility)
12+
13+
## New Services Added
14+
15+
### Immediate Execution Services (`--run`)
16+
17+
| Service Name | Profile | Command | Purpose |
18+
| ----------------------------- | ---------------- | ----------------------------------------- | ----------------------------- |
19+
| `export-trakt-run-watched` | `run-watched` | `--run --export watched --mode normal` | Export watched movies only |
20+
| `export-trakt-run-all` | `run-all` | `--run --export all --mode complete` | Export all data (recommended) |
21+
| `export-trakt-run-collection` | `run-collection` | `--run --export collection --mode normal` | Export collection only |
22+
| `export-trakt-run-ratings` | `run-ratings` | `--run --export ratings --mode complete` | Export ratings only |
23+
| `export-trakt-run-watchlist` | `run-watchlist` | `--run --export watchlist --mode normal` | Export watchlist only |
24+
| `export-trakt-run-shows` | `run-shows` | `--run --export shows --mode complete` | Export shows only |
25+
26+
### Scheduled Execution Services (`--schedule`)
27+
28+
| Service Name | Profile | Schedule | Command | Purpose |
29+
| ------------------------------ | ----------------- | ------------------ | ---------------------------------------------------------- | ---------------------- |
30+
| `export-trakt-schedule-6h` | `schedule-6h` | Every 6 hours | `--schedule "0 */6 * * *" --export all --mode complete` | Production scheduler |
31+
| `export-trakt-schedule-daily` | `schedule-daily` | Daily at 2:30 AM | `--schedule "30 2 * * *" --export all --mode complete` | Daily backup |
32+
| `export-trakt-schedule-weekly` | `schedule-weekly` | Sundays at 3:00 AM | `--schedule "0 3 * * 0" --export all --mode complete` | Weekly backup |
33+
| `export-trakt-schedule-15min` | `schedule-15min` | Every 15 minutes | `--schedule "*/15 * * * *" --export watched --mode normal` | High-frequency testing |
34+
| `export-trakt-schedule-custom` | `schedule-custom` | Configurable | Custom via env vars | Custom schedule |
35+
36+
## Profile Organization
37+
38+
### New Profiles
39+
40+
- **Immediate Execution**: `run`, `run-watched`, `run-all`, `run-collection`, `run-ratings`, `run-watchlist`, `run-shows`
41+
- **Scheduled Execution**: `schedule`, `schedule-6h`, `schedule-daily`, `schedule-weekly`, `schedule-15min`, `schedule-test`, `schedule-custom`
42+
- **Legacy Compatibility**: `legacy`, `legacy-scheduled`
43+
44+
### Updated Profiles
45+
46+
- **Default/Export**: Maintained for backward compatibility, now also tagged as `legacy`
47+
- **Complete/Initial**: Now also tagged as `legacy`
48+
- **Scheduled**: Now tagged as `legacy-scheduled`
49+
50+
## Configuration Changes
51+
52+
### Removed Obsolete Version
53+
54+
```yaml
55+
# REMOVED
56+
version: "3.8"
57+
```
58+
59+
The `version` attribute is no longer needed in modern Docker Compose.
60+
61+
### Enhanced Custom Scheduler
62+
63+
The `schedule-custom` service now properly handles environment variables:
64+
65+
```yaml
66+
export-trakt-schedule-custom:
67+
<<: *export-trakt-base
68+
profiles: ["schedule-custom"]
69+
container_name: export-trakt-schedule-custom
70+
restart: unless-stopped
71+
environment:
72+
- TZ=UTC
73+
- CUSTOM_SCHEDULE=${SCHEDULE:-0 */6 * * *}
74+
- CUSTOM_EXPORT_TYPE=${EXPORT_TYPE:-all}
75+
- CUSTOM_EXPORT_MODE=${EXPORT_MODE:-complete}
76+
entrypoint: ["/bin/sh", "-c"]
77+
command:
78+
- |
79+
/app/export-trakt --schedule "$${CUSTOM_SCHEDULE}" --export "$${CUSTOM_EXPORT_TYPE}" --mode "$${CUSTOM_EXPORT_MODE}"
80+
```
81+
82+
## Usage Examples
83+
84+
### Quick Commands
85+
86+
```bash
87+
# Test configuration
88+
docker compose --profile run-watched up
89+
90+
# Export all data once
91+
docker compose --profile run-all up
92+
93+
# Start production scheduler
94+
docker compose --profile schedule-6h up -d
95+
96+
# Custom schedule
97+
SCHEDULE="0 */4 * * *" EXPORT_TYPE="watched" EXPORT_MODE="normal" \
98+
docker compose --profile schedule-custom up -d
99+
```
100+
101+
### Migration from Legacy
102+
103+
| Old Command | New Equivalent |
104+
| ------------------------------------------ | -------------------------------------------- |
105+
| `docker compose up` | `docker compose --profile run-watched up` |
106+
| `docker compose --profile complete up` | `docker compose --profile run-all up` |
107+
| `docker compose --profile scheduled up -d` | `docker compose --profile schedule-6h up -d` |
108+
109+
## Documentation Added
110+
111+
### New Files
112+
113+
1. **`docker/README.md`**: Comprehensive Docker usage guide
114+
2. **`docker/test-docker.sh`**: Test script for Docker functionality
115+
3. **`DOCKER_CHANGES.md`**: This file documenting changes
116+
117+
### Updated Files
118+
119+
1. **`docker-compose.yml`**: Complete restructure with new services
120+
2. **Comment section**: Detailed usage examples in the compose file
121+
122+
## Benefits
123+
124+
### For Users
125+
126+
- **Simplified Usage**: Clear profiles for different use cases
127+
- **Flexible Scheduling**: Multiple pre-configured schedules
128+
- **Better Testing**: Dedicated test profiles
129+
- **Backward Compatibility**: Legacy services still work
130+
131+
### For Development
132+
133+
- **Modular Design**: Each service has a specific purpose
134+
- **Easy Extension**: Adding new schedules is straightforward
135+
- **Clear Separation**: Different modes are clearly separated
136+
- **Maintainable**: Well-documented and organized
137+
138+
## Testing
139+
140+
The changes have been tested with:
141+
142+
- ✅ Docker Compose syntax validation (`docker compose config`)
143+
- ✅ Profile listing (`docker compose config --profiles`)
144+
- ✅ Service validation with test script
145+
- ✅ Environment variable handling
146+
- ✅ Backward compatibility
147+
148+
## Backward Compatibility
149+
150+
All existing commands continue to work:
151+
152+
- `docker compose up` (default export)
153+
- `docker compose --profile setup up` (setup)
154+
- `docker compose --profile complete up` (complete export)
155+
- `docker compose --profile scheduled up -d` (legacy scheduler)
156+
157+
## Future Enhancements
158+
159+
The new structure makes it easy to add:
160+
161+
- Additional schedule presets
162+
- Different export configurations
163+
- Health checks
164+
- Monitoring integrations
165+
- Resource limits
166+
167+
This Docker Compose update provides a solid foundation for both current users and future feature development!

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,49 @@ This application is now built entirely in Go, providing:
9999
- Docker support
100100
- Complete Go implementation with improved performance and reliability
101101

102+
## Scheduling and Automation
103+
104+
The application supports scheduled exports using cron-like expressions through the `EXPORT_SCHEDULE` environment variable.
105+
106+
### Cron Scheduling
107+
108+
When running in `schedule` mode, the application will use the `EXPORT_SCHEDULE` environment variable to determine when to run exports:
109+
110+
```bash
111+
# Run the scheduler with a specific schedule (every 5 minutes)
112+
EXPORT_SCHEDULE="*/5 * * * *" EXPORT_MODE="complete" EXPORT_TYPE="all" ./export_trakt schedule
113+
```
114+
115+
### Using Docker Compose
116+
117+
The Docker Compose file includes a pre-configured scheduled service:
118+
119+
```bash
120+
# Run the scheduler in Docker
121+
docker compose --profile scheduled up -d
122+
```
123+
124+
This will start a container that runs exports according to the schedule defined in the `EXPORT_SCHEDULE` environment variable in the docker-compose.yml file.
125+
126+
### Customizing the Schedule
127+
128+
You can customize the schedule by modifying the `EXPORT_SCHEDULE` variable in the docker-compose.yml file:
129+
130+
```yaml
131+
environment:
132+
- EXPORT_SCHEDULE=0 4 * * * # Run daily at 4 AM
133+
- EXPORT_MODE=complete
134+
- EXPORT_TYPE=all
135+
```
136+
137+
Common cron schedule examples:
138+
139+
- `*/5 * * * *`: Every 5 minutes
140+
- `0 * * * *`: Every hour
141+
- `0 4 * * *`: Every day at 4 AM
142+
- `0 4 * * 0`: Every Sunday at 4 AM
143+
- `0 4 1 * *`: On the 1st day of each month at 4 AM
144+
102145
## Project Structure
103146

104147
The Go implementation follows a modern application structure:

0 commit comments

Comments
 (0)