Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(orchestrator): pause/unpause/delete sync #2289

Merged
merged 4 commits into from
Jun 10, 2024

Conversation

TBonnin
Copy link
Collaborator

@TBonnin TBonnin commented Jun 7, 2024

Adding way to pause/unpause/delete a schedule in the orchestrator
Also allowing to create a schedule in paused state. This is going to be required to support sync auto_start

Issue ticket number and link

Checklist before requesting a review (skip if just adding/editing APIs & templates)

  • I added tests, otherwise the reason is:
  • I added observability, otherwise the reason is:
  • I added analytics, otherwise the reason is:

@@ -15,7 +15,8 @@ interface ScheduleStateTransition {
export const validScheduleStateTransitions = [
{ from: 'STARTED', to: 'PAUSED' },
{ from: 'STARTED', to: 'DELETED' },
{ from: 'PAUSED', to: 'STARTED' }
{ from: 'PAUSED', to: 'STARTED' },
{ from: 'PAUSED', to: 'DELETED' }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed state transition. Deleting a paused schedule should be allowed

@TBonnin TBonnin force-pushed the tbonnin/orchestrator-schedule-pause branch from 1529f72 to aba00f1 Compare June 7, 2024 19:22
@@ -344,7 +370,6 @@ export class OrchestratorClient {
}
}

//TODO: rename to cancelTask?
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we are gonna need a cancelSync.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what you mean by this exactly?

Copy link
Collaborator Author

@TBonnin TBonnin Jun 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cancel function is cancelling a task (aka: a sync execution). Yesterday I though we might need to have a cancelSchedule so I added a TODO to rename the existing function to cancelTask. But it happens that we don't cancel schedule (which are only paused/unpaused or deleted), only tasks/jobs. So keeping the name cancel for the function is ok for now

@TBonnin TBonnin force-pushed the tbonnin/orchestrator-schedule-pause branch from aba00f1 to af26ce7 Compare June 7, 2024 19:55
Copy link
Member

@khaliqgant khaliqgant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question inline

Copy link
Collaborator

@bodinsamuel bodinsamuel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎷

if (schedule.isErr()) {
return res.status(500).json({ error: { code: 'recurring_failed', message: schedule.error.message } });
}
return res.status(201).json({ scheduleId: schedule.value.id });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: 200 might be more accurate

@TBonnin TBonnin force-pushed the tbonnin/orchestrator-schedule-pause branch from 01ad8ca to be91544 Compare June 10, 2024 11:52
@TBonnin TBonnin merged commit a30d2bd into master Jun 10, 2024
20 checks passed
@TBonnin TBonnin deleted the tbonnin/orchestrator-schedule-pause branch June 10, 2024 12:53
TBonnin added a commit that referenced this pull request Jun 10, 2024
Built on top of #2289 (please
review it first)

Implementing `runSyncCommand` in orchestrator.

I am not sure I understand the split of responsibility between
`sync.client` and `orchestrator.service`. `sync.client runSyncCommand`
is called by `orchestration.service runSyncCommand` but it is also
called directly in a few places: for example
[here](https://github.com/NangoHQ/nango/blob/dee08827d78616c013c4f3e27ddad53f46a7a298/packages/jobs/lib/crons/autoIdleDemo.ts#L81)
and
[here](https://github.com/NangoHQ/nango/blob/dee08827d78616c013c4f3e27ddad53f46a7a298/packages/server/lib/controllers/sync.controller.ts#L746).
Same thing happens with the creation of sync schedules where there are 3
mains path to `startContinuous`, `deploys` goes through the
`orchestrator.service` but `connectionCreatedHook` calls the
`sync.client` directly 😢
This make it very hard to have clean transition code. 
I have created a temporary function to take care of the feature flag
branching. Code will be refactored once temporal is removed.

For now no schedule is being created in the orchestrator so all commands
would fail if the flag is turned on.
Next PR will add the creation of schedules.

## Checklist before requesting a review (skip if just adding/editing
APIs & templates)
- [ ] I added tests, otherwise the reason is: 
- [ ] I added observability, otherwise the reason is:
- [ ] I added analytics, otherwise the reason is:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants