Skip to content
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

POST /job can now accept an array of jobs #500

Merged
merged 1 commit into from
Mar 5, 2015
Merged

POST /job can now accept an array of jobs #500

merged 1 commit into from
Mar 5, 2015

Conversation

ItalyPaleAle
Copy link
Contributor

POST /job can now accept an array of jobs. The format is as you would expect:

$ curl -H "Content-Type: application/json" -X POST -d     '[{
       "type": "email",
       "data": {
         "title": "welcome email for tj",
         "to": "tj@learnboost.com",
         "template": "welcome-email"
       },
       "options" : {
         "attempts": 5,
         "priority": "high"
       }
     },
     {
       "type": "",
       "data": {
         "title": "welcome email for tj",
         "to": "tj@learnboost.com",
         "template": "welcome-email"
       },
       "options" : {
         "attempts": 5,
         "priority": "high"
       }
     }]' http://localhost:3000/job

# Response: (status code: 400)
[
  {
    "message": "job created",
    "id": 772
  },
  {
    "error": "Must provide job type"
  }
]

Some notes:

  1. If only an object is provided, the behaviour is exactly like before
  2. If an array is provided, the response is an array with the response from each job creation, in the same order as the request array.
  3. In case of error, previous successes are reported. The last element of the array is an error object, and no more jobs are scheduled.

@behrad
Copy link
Collaborator

behrad commented Jan 16, 2015

thank you @EgoAleSum
I'll merge this into 0.9.0

@ItalyPaleAle
Copy link
Contributor Author

Thanks to you!
PS: why the "Duplicate" label?

@ItalyPaleAle
Copy link
Contributor Author

PS2 could you also consider #497 ?

@ItalyPaleAle
Copy link
Contributor Author

Oh ok, I found out about #334.
I still believe that my PR has some advantages, though, as it still returns the ids of successfully created jobs in case of error. Additionally, it doesn't depend on async (I made sure not to add more NPM modules).

@behrad
Copy link
Collaborator

behrad commented Jan 16, 2015

thats ok since I'd let in lodash before... I'll take advantage of less complicated code for this

@ItalyPaleAle
Copy link
Contributor Author

Ok, I'd still ask them if it's possible to include the IDs of successfully scheduled jobs. That's very important for us, for example, as I'll be using this code to schedule 10 future tasks which I need to be able to cancel before they're executed.

@behrad
Copy link
Collaborator

behrad commented Mar 5, 2015

we can bring in this test https://github.com/LearnBoost/kue/pull/334/files#r25875077

behrad added a commit that referenced this pull request Mar 5, 2015
@behrad behrad merged commit 90d902b into Automattic:master Mar 5, 2015
@ItalyPaleAle
Copy link
Contributor Author

Thanks for the merge :) I'll port the test later today!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants