Fix BASE_URL config loading, add tasks/projects; robust .env path resolution
- Config: try ENV_FILE, .env, ../.env for loading; trim trailing slash from BaseURL - Log BASE_URL at server startup for verification - .env.example: document BASE_URL - Tasks, projects, tags, migrations and related API/handlers Made-with: Cursor
This commit is contained in:
@@ -15,6 +15,8 @@ import (
|
||||
|
||||
const TypeReminder = "reminder:send"
|
||||
const TypeSubscriptionSync = "subscription:sync"
|
||||
const TypeTaskReminder = "task_reminder:send"
|
||||
const TypeRecurringTask = "recurring_task:generate"
|
||||
|
||||
type ReminderPayload struct {
|
||||
EventID uuid.UUID `json:"event_id"`
|
||||
@@ -54,10 +56,49 @@ func (s *Scheduler) ScheduleReminder(_ context.Context, eventID, reminderID, use
|
||||
return nil
|
||||
}
|
||||
|
||||
type TaskReminderPayload struct {
|
||||
TaskReminderID uuid.UUID `json:"task_reminder_id"`
|
||||
TaskID uuid.UUID `json:"task_id"`
|
||||
OwnerID uuid.UUID `json:"owner_id"`
|
||||
}
|
||||
|
||||
type RecurringTaskPayload struct {
|
||||
TaskID uuid.UUID `json:"task_id"`
|
||||
OwnerID uuid.UUID `json:"owner_id"`
|
||||
}
|
||||
|
||||
type SubscriptionSyncPayload struct {
|
||||
SubscriptionID string `json:"subscription_id"`
|
||||
}
|
||||
|
||||
func (s *Scheduler) ScheduleTaskReminder(_ context.Context, reminderID, taskID, ownerID uuid.UUID, triggerAt time.Time) error {
|
||||
payload, err := json.Marshal(TaskReminderPayload{
|
||||
TaskReminderID: reminderID,
|
||||
TaskID: taskID,
|
||||
OwnerID: ownerID,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("marshal task reminder payload: %w", err)
|
||||
}
|
||||
task := asynq.NewTask(TypeTaskReminder, payload)
|
||||
_, err = s.client.Enqueue(task,
|
||||
asynq.ProcessAt(triggerAt),
|
||||
asynq.MaxRetry(3),
|
||||
asynq.Queue("reminders"),
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *Scheduler) EnqueueRecurringTask(ctx context.Context, taskID, ownerID uuid.UUID) error {
|
||||
payload, err := json.Marshal(RecurringTaskPayload{TaskID: taskID, OwnerID: ownerID})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
task := asynq.NewTask(TypeRecurringTask, payload)
|
||||
_, err = s.client.Enqueue(task, asynq.MaxRetry(3), asynq.Queue("default"))
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *Scheduler) EnqueueSubscriptionSync(ctx context.Context, subscriptionID string) error {
|
||||
payload, err := json.Marshal(SubscriptionSyncPayload{SubscriptionID: subscriptionID})
|
||||
if err != nil {
|
||||
@@ -112,4 +153,8 @@ func (NoopScheduler) ScheduleReminder(_ context.Context, _, _, _ uuid.UUID, _ ti
|
||||
return nil
|
||||
}
|
||||
|
||||
func (NoopScheduler) ScheduleTaskReminder(_ context.Context, _, _, _ uuid.UUID, _ time.Time) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (NoopScheduler) Close() error { return nil }
|
||||
|
||||
Reference in New Issue
Block a user