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

Reverse delete deployment operation if reMapImagesToDeps() fails #246

Open
nathanielrindlaub opened this issue Aug 10, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@nathanielrindlaub
Copy link
Member

  // NOTE: this function is called by the task handler
  static async deleteDeployment(
    { cameraId, deploymentId }: gql.DeleteDeploymentInput,
    context: Context,
  ): Promise<HydratedCameraConfig> {
Comment
    try {
      const { project, camConfig } = await retry(
        async () => {
          // find camera config
          const [project] = await ProjectModel.getProjects(
            { _ids: [context.user['curr_project']!] },
            context,
          );
          const camConfig = project.cameraConfigs.find((cc) => idMatch(cc._id, cameraId))!;

          // filter out deployment, sort remaining ones, and save project
          camConfig.deployments = sortDeps(
            camConfig!.deployments.filter(
              (dep) => !idMatch(dep._id!, deploymentId),
            ) as typeof camConfig.deployments,
          );

          await project.save();
	          return { project, camConfig };  // TODO: do we need to return the project and cam config here??
        },
        { retries: 2 },
      );
      // TODO: we need to reverse the above operation if reMapImagesToDeps fails!
      await ProjectModel.reMapImagesToDeps({ projId: project._id, camConfig });
      return camConfig;
    } catch (err) {
      if (err instanceof GraphQLError) throw err;
      throw new InternalServerError(err as string);
    }
  } 
@nathanielrindlaub nathanielrindlaub added the bug Something isn't working label Aug 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant