feat: add arguments to created commands

This commit is contained in:
Valentin Kaelin 2019-12-16 20:51:46 +01:00
parent 46aed5a435
commit d106e84db1
2 changed files with 11 additions and 7 deletions

View file

@ -7,8 +7,9 @@ const Match = use('App/Models/Match')
class DeleteMatch extends Command { class DeleteMatch extends Command {
static get signature() { static get signature() {
return ` return `
delete:match delete:match
{ field : Delete row if entered field is null } { field : Field to check }
{ value?=null : Value of the field, if true: delete match }
` `
} }
@ -21,7 +22,7 @@ class DeleteMatch extends Command {
const nbMatchesBefore = await Match.count() const nbMatchesBefore = await Match.count()
const matches = await Match.all() const matches = await Match.all()
for (const match of matches.toJSON()) { for (const match of matches.toJSON()) {
await Match.where('_id', match._id).where(args.field, null).delete() await Match.where('_id', match._id).where(args.field, args.value).delete()
} }
const nbMatchesAfter = await Match.count() const nbMatchesAfter = await Match.count()
Database.close() Database.close()

View file

@ -9,7 +9,10 @@ const Queue = use('Bee/Queue')
class EditMatch extends Command { class EditMatch extends Command {
static get signature() { static get signature() {
return 'edit:match' return `
edit:match
{ concurrent?=10 : Number of concurrent jobs }
`
} }
static get description() { static get description() {
@ -19,8 +22,8 @@ class EditMatch extends Command {
/** /**
* Create edit-matches Queue * Create edit-matches Queue
*/ */
async createQueue() { createQueue(concurrent) {
Queue.get('edit-matches').process(2, async (job) => { Queue.get('edit-matches').process(concurrent, async (job) => {
// Get stats from Riot API // Get stats from Riot API
const matchRiot = await Jax.Match.get(job.data.gameId, job.data.region) const matchRiot = await Jax.Match.get(job.data.gameId, job.data.region)
const account = { const account = {
@ -48,7 +51,7 @@ class EditMatch extends Command {
async handle(args, options) { async handle(args, options) {
console.time('EditMatches') console.time('EditMatches')
this.createQueue() this.createQueue(args.concurrent)
// All matches from the db // All matches from the db
const matches = await Match.all() const matches = await Match.all()