-
Notifications
You must be signed in to change notification settings - Fork 74
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
arrive-server use cases #325
Comments
Hey @tgwizard , can you tell me a bit more about why you want to use a CSV for these use cases? You can run a Task with a subset of a large db table by specifying an ActiveRecord relation for module Maintenance
class SubsetOrderTask < MaintenanceTasks::Task
def collection
Order.where(user_id: 123)
# or, Order.where(id: 10000..20000)
end
def count
collection.count
end
def process(order)
# Do something
end
end
end As for concurrency, it's definitely something that's on our radar, but the gem isn't able to handle that yet. You can indeed write separate tasks to handle different subsets of the data and run them concurrently. I'm realizing now that CSV Tasks might have been appealing because you can customize which collection the Task is processing? So yes, if you wanted to, you could export a CSV with ids for all the orders you wanted to process, and then upload this to a CSV-processing Task. This way you could reuse a single Task across multiple datasets BUT the drawback is that you can only run a single instance of a Task at a time, so you wouldn't be able to achieve this concurrently. (So if concurrency is important, your best bet right now would be to just write separate Tasks for different datasets). Let me know if this answers your question(s) or if I've misunderstood anything 😄 |
Hmm, right, that Similarly, the extract-order-ids-to-csv and run that as a CSV task kinda works, but that doesn't guarantee that all a user's orders have been migrated (if there are new orders added after the CSV has been generated). A CSV that contains the user IDs to run for would be a good middleground, but then the maintenance task would still need to adjust the |
Ah, gotcha. So instead of having it be "CSV as a way to define a collection of rows to process", it would be "CSV as a way to define parameters that can be used in conjunction with another type of collection, like an ActiveRecord relation". I think this would warrant a new type of task entirely. The CSV tasks are really intended to provide a collection for iteration, as opposed to allowing users to build new collections off of the contents of the CSV. (I realize that https://github.com/Shopify/super_maintenance/issues/8 is misleading because we talk about CSVs within the context of writing recurring tasks that take params, and is different from the usage of the CSV Task that is currently being built into the gem as it stands today). As a workaround, to achieve:
You could commit a CSV to your filesystem, and write a Task that does |
Right, ideally we wouldn't need to deploy any changes to maintenance tasks or CSV files to run the task for a different subset of data. Ideally we wouldn't need to edit a CSV and upload that to target a new subset either - a UI with some kind of parameter input would be the ideal for us. |
What if you run the task and then cancel it manually after some time? That works for some variation of subset of records. Also we're not making this a public API just yet, but the way CsvCollection works may give you a seam to get into. It basically just defines a module Maintenance
class SubsetTask < MaintenanceTasks::Task
csv_collection
def collection
csv = super
SomeActiveRecord.where(user_id: csv.map {|row| row['user_id'] })
end
def process(record)
#
end
end
end
Not sure how likely we are to break this API, so you may want to add a test that checks that your maintenance task works with |
Oh, that actually sounds like a good option for us @etiennebarrie! Slightly tedious to create a CSV when adjusting which users to target, but that is likely still less tedious than the other ways we have of doing this. |
That's a super interesting point @etiennebarrie - obviously it's not-so-nice to hack with how I wonder if we could develop an API that looks something like this: module Maintenance
class SubsetTask < MaintenanceTasks::Task
with_params
def collection
SomeActiveRecord.where(user_id: params[:user_ids])
end
def process(record)
#
end
end
end And then in the UI, you would be expected to attach a CSV like this:
And then
|
Although arguably for ^ if you wanted to support multiple parameters, you'd have to do something like this:
which is stretching the design of CSVs since each row is not actually a cohesive element. Maybe a different input type would work even better, like JSON? {
"shop_ids": [1, 2, 3],
"product_ids": [100, 101, 102]
} |
Closing this, custom parameter support has been addressed. |
Moving the conversation from https://github.com/Shopify/super_maintenance/issues/8#issuecomment-775932361 over to our existing repo
From @tgwizard :
The text was updated successfully, but these errors were encountered: