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

Add "safe" alternatives for creation functions #11

Open
richierocks opened this issue Jun 13, 2019 · 0 comments
Open

Add "safe" alternatives for creation functions #11

richierocks opened this issue Jun 13, 2019 · 0 comments

Comments

@richierocks
Copy link
Contributor

The API allows you to create projects and tasks with the same name as existing projects/tasks.

It would be useful to have safe alternatives that check if the thing already exists, and only create it if it doesn't.

For example, a safe version of asn_projects_create_in_team() could look like this.

asn_safe_projects_create_in_team <- function(team, name, ..., options = list()) {
  project <- asn_projects_find_by_team(team = team) %>% 
    filter(name == !!name)
  
  if(nrow(project) > 0) {
    warning(sprintf("A project with name %s already exists.", name))
    project_id <- get_gid(project)[[1]]
    return(asn_projects_find_by_id(project_id))
  }
  
  asn_projects_create_in_team(team = team, name = name, ..., options)
}

The use case I'm thinking about is that I want to have an airflow task that pulls data on exercise issues each day, and add them to a project. Since most of the tasks will already exist from the previous day, I want to check whether or not it already exists before creating it.

I think that this sort of safe checking is a common enough pattern that it ought to exist here. If not, I can put it in dcasana instead.

cc: @ramnathv

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

No branches or pull requests

1 participant