cosmo/backend/scripts/add_planetary_events_job.sql

64 lines
1.9 KiB
SQL

-- Add calculate_planetary_events task to the scheduled tasks
-- This task will calculate planetary events (conjunctions, oppositions) using Skyfield
-- Example 1: Calculate events for all major planets (365 days ahead)
INSERT INTO tasks (name, description, category, parameters, status, schedule_config)
VALUES (
'calculate_planetary_events',
'计算太阳系主要天体的合、冲等事件(每周执行一次)',
'data_sync',
'{
"days_ahead": 365,
"clean_old_events": true,
"calculate_close_approaches": false
}'::json,
'active',
'{
"type": "cron",
"cron": "0 2 * * 0"
}'::json
)
ON CONFLICT (name) DO UPDATE SET
parameters = EXCLUDED.parameters,
schedule_config = EXCLUDED.schedule_config;
-- Example 2: Calculate events for inner planets only (30 days ahead, with close approaches)
-- INSERT INTO tasks (name, description, category, parameters, status, schedule_config)
-- VALUES (
-- 'calculate_inner_planetary_events',
-- '计算内行星事件(包括近距离接近)',
-- 'data_sync',
-- '{
-- "body_ids": ["199", "299", "399", "499"],
-- "days_ahead": 30,
-- "clean_old_events": true,
-- "calculate_close_approaches": true,
-- "threshold_degrees": 5.0
-- }'::json,
-- 'active',
-- '{
-- "type": "cron",
-- "cron": "0 3 * * *"
-- }'::json
-- )
-- ON CONFLICT (name) DO NOTHING;
-- Query to check the task was added
SELECT id, name, description, status, parameters, schedule_config
FROM tasks
WHERE name = 'calculate_planetary_events';
-- Query to view calculated events
-- SELECT
-- ce.id,
-- ce.title,
-- ce.event_type,
-- ce.event_time,
-- cb.name as body_name,
-- ce.details,
-- ce.created_at
-- FROM celestial_events ce
-- JOIN celestial_bodies cb ON ce.body_id = cb.id
-- WHERE ce.source = 'skyfield_calculation'
-- ORDER BY ce.event_time;