Thursday, April 25, 2019

Running Custom Backfill Command In MVC App

I have a .NET MVC (Core 2.2) app and I'm looking to run a backfill job to fix some things up. I'm having trouble figuring out where I can put this code. I could create a web endpoint to run this, but that feels weird for something that's just a one-time management task. I could create another project and set it up for all my database connections and such, but that also seems like overkill.

In Java, I could create a second main method to do this. In Rails, I'd create a rake task in the project (https://guides.rubyonrails.org/command_line.html#custom-rake-tasks). With Django, I'd create a custom django-admin management command (https://docs.djangoproject.com/en/2.2/howto/custom-management-commands/). There doesn't seem to be any place to put code I want to run as a one-off within the environment of my app (with its database connections and such).

It has a place for DB migrations that will be run in the environment of the app, but I can't see where I can place a task that would run something custom (and trying to google with terms like "task" or "job" is kinda futile since async uses "task" and "job" just comes up with employment results).

Basically, if I have something that wants to do:

public void Fixup() { for (var thing in _dbContext.Things.toList()) { var toUpdate = //get from some data source thing.field = toUpdate; _dbContext.SaveChanges(); } } 

I want to be able to use my setup environment to run something like that.

Running Custom Backfill Command In MVC App Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team