ember-data-copyable icon indicating copy to clipboard operation
ember-data-copyable copied to clipboard

TaskInstance '__DS_COPY_TASK_RUNNER__' was canceled because it belongs to a 'drop' Task that was already running.

Open songoo opened this issue 8 years ago • 10 comments

Hello.

I am using ember-data-copyable (0.2.1) to copy models, its very cool! And had no problems till today :( when I tried to copy same model in multiple times.

I have Promise.all(promises), in every of that promises I copy one or more models, but those are always the same models for all promises.

For example, I have 3 models (taskAsignments) , and I want copy all 3 of them in for example 6 promises.

What I encounter is, that all 3 models are copied in firstProcessedPromise and will fail in all other (five) promises with message :

TaskCancelation: TaskInstance 'DS_COPY_TASK_RUNNER' was canceled because it belongs to a 'drop' Task that was already running. For more information, see: http://ember-concurrency.com/#/docs/task-cancelation-help

I tried to rewrite Promise.all with reduce, so all 6 promises would be called in synchronized way, but result was same sadly. I also tried deep and not deep .copy with same result.

If possible please advice if have any idea.

songoo avatar Aug 30 '17 16:08 songoo

I tried to replace .copy with manual (create record + calling all setters) copping and it went with no error. Also tried to get some info from ember slack, here is response, but not sure if it helps :

it’s hard to say without seeing some of the code, but that’s an error that will result from a promise rejection after a task instance has been coerced to a promise (usually by calling .then() or .catch() from a task instance, or by passing the task instance to something like an RSVP.hash or returning it from a route lifecycle hook). this is mentioned in the docs here: http://ember-concurrency.com/api/global.html#didCancel

songoo avatar Aug 30 '17 17:08 songoo

I have this issue to when attempting to copy 2+ of the same model at once. Seems to be that only the last scheduled copy is performed all other copies are cancelled with the error outlined above.

roscorcoran avatar Oct 06 '17 11:10 roscorcoran

Are you guys trying to copy the same model instance multiple times or are you copying different instances of the same model type?

offirgolan avatar Oct 07 '17 21:10 offirgolan

Hi. "same model instance multiple times", yes i get one assigment from database, then run 3 promises in same time and each of them will try to make its own copy of that exact assigment.

songoo avatar Oct 09 '17 00:10 songoo

Makes sense. The copy task runner has a drop concurrency task policy. That means it will only execute the first request and ignore the rest until it's done running.

I need to investigate other concurrency policies before just removing this one due to unforeseen implications. In the mean time, you guys will need to chain your requests.

async copyModels(model) {
  await model.copy();
  await model.copy();
  await model.copy();
}

offirgolan avatar Oct 09 '17 17:10 offirgolan

I also tried synchronous promises(with reduce), it did not help (and i was sure it will) .

songoo avatar Oct 09 '17 22:10 songoo

Hmmmm thats pretty odd. I'll investigate this further in the next week or two. Pretty swamped at the moment.

offirgolan avatar Oct 09 '17 22:10 offirgolan

@offirgolan Would you be willing to entertain a PR that makes it possible to allow a configurable set of concurrency options?

Something like:

model.copy({concurrencyPolicy: 'keepLatest'}) //because i can't spell Enqueue

I'm not familiar enough with the guts of EC to understand if you can dynamically apply .drop or whatever, but on the mixin side we could add a different layer of abstraction to do like

[COPY_TASK_<TYPE>]: task(function*() { return this.get('COPY_TASK').perform(options)).<TYPE>()

donaldwasserman avatar Mar 21 '18 18:03 donaldwasserman

@donaldwasserman I would if there was a decent way of doing this. I'd rather not bomb the model's proto with a bunch of copy tasks for each concurrency policy.

ping @machty any thoughts on how I can support something like this?

offirgolan avatar Mar 22 '18 00:03 offirgolan

I think we shouldn't enforce any kind of concurrency policy ourselves and leave that choice to the user.

@offirgolan do you recall the reason to set the copy task concurrency policy to drop?

miguelcobain avatar Nov 26 '22 03:11 miguelcobain