how to get user context / thread id to distinguish between task sequences - locust

I have a task sequence to execute multiple times, with multiple different users. Is there something I can write into the log file to identify an action being taken by user1 vs user2?

It kind of depends on exactly what you're trying to do, but the easiest way is probably to just name your request differently, using the name= parameter. (assuming you dont have lots of users)
e.g
self.client.post("/login", data={ "username": username }, name=f"/login {username}")

What I did was to add in my output to a custom CSV file the login id for the user, and an iteration counter. This way I can uniquely distinguish between task sequences because they are identified by email address and the counter.
This works for non-distributed testing.

Related

CQRS - How to handle if a command requires data from db (query)

I am trying to wrap my head around the best way to approach this problem.
I am importing a file that contains bunch of users so I created a handler called
ImportUsersCommandHandler and my command is ImportUsersCommand that has List<User> as one of the parameters.
In the handler, for each user that I need to import I have to make sure that the UserType is valid, this is where the confusion comes in. I need to do a query against the database, to get list of all possible user types and than for each user I am importing, I want to verify that the user type id in the import matches one that is in the db.
I have 3 options.
Create a query GetUserTypesQuery and get the rest of this and then pass it on to the ImportUsersCommand as a list and verify inside the command handler
Call the GetUserTypesQuery from the command itself and not pass it (command calling another query)
Do not create a GetUsersTypeQuery and just do the query results within the command (still a query but no query/handler involved)
I feel like all these are dirty solutions and not the correct way to apply CQRS.
I agree option 1 sounds the best but would maybe suggest adding a pre handler to validate your input?
So ImportUsersCommandHandler deals with importing you data (and only that) and add a handler that runs before that validates (in your example, checks the user types and maybe other stuff) and bails out of it does not pass. So it queries the db, checks the usertypes and does whatever it needs to if it fails. Otherwise it just passes down to your business handler (ImportUsersCommandHandler).
I am used to using Mediatr in NET Core and this pattern works well (this is what we do) so sorry if this does not fit with your environment/setup!

Email Triggered With Success Row count in Target Using informatica

I need to trigger an email with all the stats like Count of Rows which are successfully loaded in the target, Failed rows count with the help of Informatica Powercenter.
So where can I find this information for the Workflow and how can I used that information to trigger the email to respective people.
There is an email task present in the Informatica which I am hoping I can use that.
You can use built-in session parameters to collect session run details, e.g.:
$PMSessionName: Name of the Informatica session.
$PMSourceName#TableName: Name of the source table name.
$PMTargetName#TableName: Name of the target table name.
$PMSourceQualifierName#numAffectedRows: Number of records returned
from source.
$PMTargetName#numAffectedRows: Number of record
inserted/updated into the target table.
$PMTargetName#numRejectedRows: Number of records error out in target.
Here's more info: http://powercenternotes.blogspot.com/2014/01/an-etl-framework-for-operational.html
you are right. You can use e mail task. Or you can use post session email command to send mail with statistics - like output file, counts etc.
I need to trigger an email with all the stats like Count of Rows which are successfully loaded in the target, Failed rows count with the help of Informatica Powercenter.
Since you are looking for session level count, you may want to look into using post-session email and using the email variables.
...trigger the email to respective people. There is an email task present in the Informatica which I am hoping I can use that.
If you need to use email task, in the link going to email task, you can double-click on the link, and set link condition to trigger which email task to go towards.

Dialog Flow ( Api.ai ) Conversation in chatbot

I am having a welcome intent and it allows user to select three different actions. Ex: Welcome! you can print your firstname, you can print your lastname or you can print your zipcode. If User select or enter last name then it should call the last name intent. So we are providing multiple options at welcome intent itself and user can choose any one of them.
Based on the action selected by user, the conversation should occur.
Please help me how to achieve this.
You are giving the user the option of proceeding by providing their first name, their last name or their zip code.
To capture their response, you will need to create three intents:
Capture First Name
Capture Last Name
Capture Zip Code
For each intent, you would provide a series of example phrases showing how the user might express each thing. For example, "Capture First Name" might contain examples like:
"My first name is Dan"
"Dan"
"Dan is my first name"
I'd recommend providing around 10 examples for each intent.
Dialogflow provides a system entity for zip codes, so it will be able to automatically extract the zip code from the "Capture Zip Code" intent.
However, to make the first and last name intents work, you'll need to create entities to represent the first and last names of all your users. Assuming you know these values ahead of time, you should first create each entity and then write a script to populate it from your datastore using the Dialogflow API's /entities endpoint.
Once you've created and populated these entities, add some examples that make use of them to your intents. Ensure that you highlight and annotate any entity values that are not automatically identified.
When your intents are complete, you can use Dialogflow's fulfillment to send the information they capture to your back-end.
Normally when the welcome intent triggered it will send a request to your backend through webhook,from backend you can send responses as templates or buttons and user can choose one of them ,if you are using backend here
Else in welcome intent response,use a response like you can print firstname ,you can print second name and configure intents for those and use contexts for proper flow.
In the second intent,keep one entity containing some values for first name and use a output context like frstname_output_context
In the another intent,keep one entity containing some values for last name as entity and use a output context like lsttname_output_context
Hope it clarifies using webhook and without webhook.

Using luigi to update Postgres table

I've just started using the luigi library. I am regularly scraping a website and inserting any new records into a Postgres database. As I'm trying to rewrite parts of my scripts to use luigi, it's not clear to me how the "marker table" is supposed to be used.
Workflow:
Scrape data
Query DB to check if new data differs from old data.
If so, store the new data in the same table.
However, using luigi's postgres.CopyToTable, if the table already exists, no new data will be inserted. I guess I should be using the inserted column in the table_updates table to figure out what new data should be inserted, but it's unclear to me what that process looks like and I can't find any clear examples online.
You don't have to worry about marker table much: it's an internal table luigi uses to track which task has already been successfully executed. In order to do so, luigi uses the update_id property of your task. If you didn't declared one, then luigi will use the task_id as shown here. That task_id is a concatenation of the task family name and the first three parameters of your task.
The key here is to overwrite the update_id property of your task and return a custom string that you'll know will be unique for each run of your task. Usually you should use the significant parameters of your task, something like:
#property
def update_id(self):
return ":".join(self.param1, self.param2, self.param3)
By significant I mean parameters that change the output of your task. I imagine parameters like website url o id, and scraping date. Parameters like the hostname, port, username or password of your database will be the same for any of these tasks so they shouldn't be considered significant.
Notice that without having details about your tables and the data you're trying to save its pretty hard to say how you must build that update_id string, so please be careful.

How to generate one-time-use links? Any CMS or framework solutions?

I'm making a site for a writers management company. They get tons of script submissions every day from prospective and often unsolicited writers. The new site will allow a prospective writer to submit a short logline / sample of his or her idea. This idea gets sent to an email account at the management group. If the management group likes what they see, they want to be able to approve that submission from within the email and have a unique link dispatched to the submitter to upload their full script. This link would either only work once, or only for a certain amount of time so that only the intended recipient could use it.
So, can anyone point me in the direction of some sort of (I'm assumine PHP + mySQL) CMS or framework that could accomplish this? I've searched a lot, but I can't seem to figure out the right way to phrase this query to a search engine.
I have moderate programming experience, but not much with PHP outside of some simple Wordpress hacks.
Thanks!
I will just give you general guidelines on a simple way to construct such a system.
I assume that the Writer is somehow Registered into the system, and his/her profile contains a valid mail address.
So, when he submits the sample, you would create an entry on the "Sample" table. Then you would mail a Manager with the sample and a link. This link would point to a script giving the database "id" of the sample as a parameter (this script should verify that the manager is logged on -- if not, show the login screen and after successful login redirect him back).
This script would then be aware of the Manager's intention to allow the Writer to submit his work. Now the fun begins.
There are many possibilities:
You can create an entry in an appropriate "SubmitAuthorizations" DB table containing the id of the Writer and the date this authorization was given (ie, the date when the row was added to your DB). Then you simply send a mail to the Writer with a link like "upload.php?id=42", where the id is the authorization id. This script would check if the logged user is the correct Writer, and if he is within the allowed timeframe (by comparing the stored "authorization date" and the current date).
The next is the one I prefer: without a special table just for handling something trivial (let's say you will never want to "edit" an authorization, nor "cancel" it, but it may still "expire"). You simply simply give the Writer a link with 2 parameters: the date the authorization was given and an authorization key, like: "upload.php?authDate=20091030&key=87a62d726ef7..."
Let me explain how it works.
The script would first verify if the Writer is logged on (if not, show the login page with a redirection after successful login).
So, now it's time to validate the request: that is, check if this is not a "forged" link. How to do this? It's just a "smart" way of construction this authorization key.
You can do something like:
key = hash(concat(userId, ";", authDate, ";", seed));
Well, here hash() is what we call a "one-way function", like MD5, SHA1, etc. Then concat() is simply a string concatenation function. Finally seed is something like a "master password", completely random and that will not change (for if you change it all the issued links would stop working) just to increase security -- let's say a hacker correctly guesses you are using MD5 (which is easy) and the he tries to hack your system by hashing some combinations of the username and the date.
Also, for a request to be valid, it must be in the correct time frame.
So, if both the key is valid, and the date is within the time frame, you are able to accept an upload.
Some points to note:
This is a very simple system, but might be exactly what you need.
You should avoid MD5 for the hashing function, take something like SHA1 instead.
For the link sent to the Writer, you could "obfuscate" the parameter names, ie, call them "k" for the "key" and "d" for the "authDate".
For the date, you could chose another format, more "cryptic", like the unix epoch.
Finally, you can encode the parameters with something like "base64" (or simply apply some character replacing function like rot13 for instance, but that take digits into account aswell) just in order to make them more difficult to guessing
Just for completeness, in the validation script you can also check if the Writer has already sent a file on the time frame, thus making it impossible to him to send many files within the time frame.
I have recently implemented something like this twice on the company I work for, for two completely different uses. Once you get the idea, it is extremelly simple to implement it -- maybe less than 10 lines of code for the whole key-generation and validation process.
On one of them, the agent equivalent to your Writer had no account into the system (actually it would be his first contact with the system) -- there was only his "profile" on the system, managed by someone else. In this case, you would have to include the "Writer"'s id on the parameters to the "Upload" script aswell.
I hope this helps, and that it was clear enough. If I find the time, I will blog about it with an working example on some language.