The problem I'm facing is:
I have a request and need to check 3 types of responses for this request. Each time I need to slightly modify my request body before sending it.
dredd --names:
info: Users > User Operations > Update User > Example 1
skip: PUT (204) myurl/users/userid-123
info: Users > User Operations > Update User > Example 2
skip: PUT (422) myurl/users/userid-123
info: Users > User Operations > Update User > Example 3
skip: PUT (429) myurl/users/userid-123
My idea was in the before hook do something like "cucumber-style":
before(/^Users > User Operations > Update User > Example (1|2|3)$/) do |myvar|
Here run loop from 1 to 3 and do necessary changes
But after several trials this doesn't seem to work, looks like ruby-hooks doesn't support variables in names.
Any ideas what would be the proper approach for this case, since having separate before-hook for every single request doesn't seem right here?
I don't think the Ruby hooks support regular expressions in the transaction names. A simple workaround would be to catch all and distinguish the transactions in the hook itself:
before_each do |transaction|
if transaction.name.match(/Example (1|2|3)$/)
...
end
end
Related
We have rest resource
/tasks/{task-type}
and only GET methods available.
GET /tasks/{task-type}
GET /tasks/{task-type}/{id}
Task entity contains meta info like created, finished, status, ref key and try counts for scheduled tasks.
Now we faced with problem, when task may contains incorrect data and its execution always failed.
Due to scheduler invoked tasks every 5 min there are a lot of errors in logs and largest try counts around 500k. The solution i found is to limit try_count to five (for example). And now we need way to manual discard try-count to zero. So i found two solutions:
1.
PATCH /tasks/{task-type}/{id}/discard-try-count - no response body
This solution look pretty simple, but violates the REST convention, because we use action(verb) in naming. But if we need to change other fields, then we will make a lot of endpoints in this style.
2a.
PATCH /tasks/{task-type}/{id}
body:
{
"tryCounts": int
}
This looks like REST want to see it and we can easy add new fields to modify, but now client can set any value for tryCount.
2b
PATCH /tasks/{task-type}/{id}
body:
{
"tryCounts": int // validate that try count can be only zero
}
Differs from the previous one by the presence of validation.
This looks like the most reliable solution. Is it really the best fit?
The non-verb convention is not a standard, you can violate it if you want to, though it can be worked around with very simple stuff, just convert the verb into a noun and you will be ok, something like:
POST /tasks/{task-type}/{id}/try-count-discarding
Another way is setting the try count to zero:
PUT /tasks/{task-type}/{id}/try-count 0
Yet another solution is combining the two, which I like the most:
PATCH /tasks/{task-type}/{id}/try-count {"op": "reset"}
Or another variant:
PATCH /tasks/{task-type}/{id} {"op": "discard-try-count"}
Hello I ma trying to submit unsubmitted quiz attempts so I can grade them. So far I have set the timefinish column in mdl_quiz_attempts which changes the attempt status to "Not yet graded", then setting fraction to 0 from NULL and state to "gradewrong" from "complete" in mdl_question_attempt_steps to simulate submission but this seems to break the site. What am I missing?
You're going to have to trace through the code for the process_finish() function in mod/quiz/attemptlib.php ( https://github.com/moodle/moodle/blob/master/mod/quiz/attemptlib.php#L2171 ) and figure out how that all works.
This is a complex process and will require a lot of DB queries / updates in order to achieve it manually.
I would strongly recommend that you write a PHP script to do this, instead of trying to handle it manually (that way you can create an instance of 'quiz_attempt' for each user's attempt, then call $attempt->process_finish() on each, in order to close the attempt properly).
Thanks. The trick is to set the timefinish column in mdl_quiz_attempts which changes the attempt status to "Not yet graded", then setting the state to "gradewrong" from "complete" in mdl_question_attempt_steps for unsubmitted responses to simulate submission. Then set a fake 0 grade to sumgrades where grades are NULL in mdl_quiz_attempts and then running a regrade in the admin panel.
I want to get all the actions for a board, but Trello limits the results to 1000. I understand the correct way to deal with this is to paginate. I've tried both before and page as keywords:
Basic Call:
https://api.trello.com/1/board/[boardID]/
?key=[key]&token=[token]
&actions=commentCard&actions_limit=1000
Alternatives:
Before:
https://api.trello.com/1/board/[boardID]/
?key=[key]&token=[token]
&actions=commentCard&actions_limit=1000&
before=[oldest_returned_action's_date]
Page:
https://api.trello.com/1/board/[boardID]/
?key=[key]&token=[token]
&actions=commentCard&actions_limit=1000&
page=[page_number]
The result never varies --- I always get back [limit] number of actions, and they're always the same no matter the call. I checked the dates in what was returned and they certainly don't respect the before parameter. I even tried lowering the limit to make sure I wasn't trying to return more than I possessed. The problem persists.
How can I correctly get all actions for a Trello board?
Actions are in reverse chronological order (newest-to-oldest), so to page through the actions on a board, you would use something like:
curl "https://api.trello.com/1/boards/${BOARD_ID}/actions/?key=${TRELLO_API_KEY}&token=${TRELLO_TOKEN}&limit=1000"
then, from the last element of the array returned by the the above, select the date or id and pass that as the before parameter in the next call, e.g.:
curl "https://api.trello.com/1/boards/${BOARD_ID}/actions/?key=${TRELLO_API_KEY}&token=${TRELLO_TOKEN}&limit=1000&before=${DATE_OR_ID_OF_LAST_ACTION}"
and repeat, passing in either the id or date of the last action as the subsequent before parameter.
References:
Paging
Board Actions
Actions Nested Resource
Screenshot 2The one screen shot of this errorissue I am building an app using api.ai , an syllabus app which tells you the syllabus, but when I invoke it with desired parameters like branch and semester I have made each individual intent for it even then I'm getting miss answers sometimes like when asked for sem 4 and branch electronics its showing sem 3 sem 4 or of other branch . I have given sem and branch as required n given few invoking statements even then getting this. Tried even training it manually for free 30s of actions on api.ai no solution please help. Not using any web hook , context , event.
Short answer - check here for screenshots http://imgur.com/a/tVBlD
Long answer - You have two options
1) Create 3 separate custom entities for each branch type (computer science, civil, communication) which you need to attach to your branch parameter
2) Using the sys.any entity and attaching it to your branch parameter; then determining what the incoming parameter value is on a server then sending back a response through a webhook.
If you go the second route, you have to create a webhook and hardcode recognized words like 'computer science' in IF statements which check the incoming parameter (sent through JSON from API.AI). This route will be more difficult but I think you will have to travel it regardless because you will have backend architecture which you access to find and return the syllabus.
Note the second route is what I did to solve a similar issue.
You can also use regex to match an item in a list which limits the amount of hardcoding and if statements you have to do.
Python regex search example
baseurl = "http://mywebsite.com:9001/"
# Parse the document
# Build the URL + File Path and Parse the Document
url = baseurl + 'Data'
xmlLink = urllib.request.urlopen(url)
xmlData = etree.parse(xmlLink)
xmlLink.close()
# Find the number of elements to cycle through
numberOfElements = xmlData.xpath("count(//myData/data)")
numberOfElements = int(numberOfElements)
types = xmlData.xpath("//myData/data")
# Search the string
i = 0
while numberOfElements > i:
listSearch= types[i].text
match = re.search(parameter, listSearch, re.IGNORECASE)
if match is None:
i += 1
else:
# Grab the ID
elementID = types[i].get('id')
i = 0
break
An simple trick would be what i did, just have an entity saved for both branch and semester , use sys.original parameters and an common phrase for provoking each intent saves up the hard work.
I have a RESTful api I am trying to consume using talend
in order to get data 2 api calls are needed, the first generates an ID for your report, which you then use to make a consecutive api call using that ID to get your data results
the issue is if the requested report in the 2nd api call has not yet completed it will return
[{data:{string:"Requested report ### has not finished processing yet, please try again later"}}]
so, i put a tJava to thread(5000) to stagger the 1st api call (tRestClient2) from the 2nd api call (tRestClient1), but I could forsee this being an issue
what i want to do is evaluate the 2nd tRest request result (tFileOutputJSON_3), and if it equals "Requested report...", then requeue the 2nd tRest request until the data is ready
here is a screenshot of my job
Like always there is ton of solutions.
But you are not far from what you want. This following design should respect your expectation :
I kept your components as I don't really know what you are doing inside(I retired tLogrow to make things concise). But I reorganized scheduling links.
tJava
|onSubjobOk
tRestClient -- >
tFileOutputJSON
|onSubjobOk
tFileInputJSON-- >
tExtractJSONFields -- > tJavaRow
|onSubjobOk
tSetGlobalVar1
|onSubjobOk
tLoop2 -- iterate (order1)-- > tRestClient -- >
tHashOutput3
| -- iterate
(order2)-- > tHashInput4 -- > tJavaRow5
| -- iterate
(order3)-- > tSleep6
|onSubjobOk
tHashInput7 -- > tFileOutputJSON
1:Use a variable to manage the loop.
2:Use a While loop. Leave declaration and iteration blank (""), and put your condition using the previously initialized variable.3:Do not use Append as you want to fetch new result at each loop.
4:Link it to your HashOutput and do not clear cache.
5:Do your work here. Do not forget to update the global variable.
6:Can be placed before the call if most calls required time before report getting ready.
7:Link it to your HashOutput too, you will be able to fetch the data that made a end to the loop.