-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor sleep 1 in migration generator to use proper timestamp handling #49
Copy link
Copy link
Open
Labels
good first issueGood for newcomersGood for newcomersrefactorStuff we should improveStuff we should improve
Description
Description
The install rake task uses sleep 1 to ensure different migration timestamps, which is fragile and can fail under various conditions (slow systems, interruptions, etc.).
Current code
lib/tasks/bunko/install.rake:21:
create_post_types_migration(skip_seo: skip_seo, json_content: json_content)
sleep 1 # Ensure different timestamps
create_posts_migration(skip_seo: skip_seo, json_content: json_content)Problems this causes
- Fragile - relies on system timing
- Slows down installation unnecessarily
- Could still collide if system is slow or task is interrupted
- Not how Rails generators handle this problem
- Fails if user Ctrl+C's during sleep
Pros of refactoring
- More reliable timestamp generation
- Faster installation
- Follows Rails patterns
- No possibility of collision
- Better user experience
Cons of refactoring
- Need to implement proper timestamp incrementing
- Slightly more complex logic
Recommended approach
Increment timestamps programmatically like Rails generators do:
base_timestamp = Time.now.utc.strftime("%Y%m%d%H%M%S")
timestamp1 = base_timestamp
timestamp2 = (Time.now.utc + 1.second).strftime("%Y%m%d%H%M%S")
# Or simpler:
timestamp1 = Time.now.utc.strftime("%Y%m%d%H%M%S")
timestamp2 = (Time.now.utc.to_i + 1).to_s.ljust(14, '0')References
lib/tasks/bunko/install.rake:21
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomersrefactorStuff we should improveStuff we should improve