I’m trying to test but I’m having a problem I can’t find a solution to, this is my test… it’s not very good I know but I need solution.
this is my method
import { Meteor } from 'meteor/meteor'
import { ValidatedMethod } from 'meteor/mdg:validated-method'
import { CallPromiseMixin } from 'meteor/didericis:callpromise-mixin'
import Journal from '../journals/journals'
import JournalDetails from '../journals/journal-details'
export const journalMigrateTotDecimal = new ValidatedMethod({
name: 'app.journalMigrateTotDecimal',
mixins: [CallPromiseMixin],
validate: null,
async run() {
if (Meteor.isServer) {
let res
console.log('start....');
let journals = await Journal.find().lean()
res = await Journal.deleteMany({})
res = await Journal.insertMany(journals)
console.log('done journal!');
let journalDetails = await JournalDetails.find().lean()
res = await JournalDetails.deleteMany({})
res = await JournalDetails.insertMany(journalDetails)
console.log('done journal details!');
return res
}
},
})
call on client
<ElButton type="primary" @click="migrateJournalData">
Journal
</ElButton>
methods: {
migrateJournalData() {
this.loading = true
journalMigrateTotDecimal
.callPromise()
.then(res => {
this.loading = false
console.log('res', res)
})
.catch(err => {
this.loading = false
console.log('err', err)
})
},
},
The problem is work more than one time. I don’t know why. I don’t know how to solve it.
Are you saying that when you click the button once, you get multiple rounds of logs on your server?
Have you checked with the debugger to see how many times the click handler fires, or how many websocket messages are sent?
Yes I console I see like picture below
I wonder if this has anything to do with using an async function?
One thing which is non-obvious about using async functions as methods, is that it implicitly calls this.unblock()
on your method, meaning that methods won’t wait for the previous call to finish before starting the next.
Not that it should be called multiple times anyway…
Have you checked with the debugger to see how many times the click handler fires, or how many websocket messages are sent?
1 Like
I forget to tell you my data collection records maybe 800000 records.
Have you checked with the debugger to see how many times the click handler fires, or how many websocket messages are sent?
1 Like
I found that 800000 records can not insert one time. So need to separate group of records smaller.
So you’ve checked this and it only fires once?
Is the method timing out and re-trying?
You could try setting the method to not retry like so:
export const journalMigrateTotDecimal = new ValidatedMethod({
name: 'app.journalMigrateTotDecimal',
mixins: [CallPromiseMixin],
applyOptions: {
noRetry: true, // <-- Tell Meteor not to retry
},
validate: null,
async run() {
// etc...
Meteor methods with better scoping, argument checking, and good defaults. - GitHub - meteor/validated-method: Meteor methods with better scoping, argument checking, and good defaults.
I try it but it still the same problem.
I can only help you further if you answer some of the questions I’ve asked or otherwise provide more information
1 Like
Now I try it work fine thank