doIf not working with session - scala

I´m trying to use Gatling, where I just want to execute some steps in the first scenario iteration, here my code
def create(): ScenarioBuilder = {
scenario(name)
.exec(session => session.set("DEBUG", debug_set))
.exec(session => session.set("client_id", session.userId))
.doIf(session => session("initialized").asOption[String].isEmpty) {
exec(Identity.getIdentityToken)
exec(session => session.set("initialized", "true"))
}
.exitHereIfFailed
.during(Duration(15, MINUTES)) {
exec(X.setupVars)
.exec(X.create)
.pause(Duration(1, SECONDS))
.exec(X.get)
}
}
}
Somehow first iteration where initialized it´s not defined it´s not getting there, since I dont see the logs the execution of the one of the steps.
Any idea what I´m doing wrong?

One dot is missing for the second exec in your doIf:
.doIf(session => session("initialized").asOption[String].isEmpty) {
exec(Identity.getIdentityToken)
.exec(session => session.set("initialized", "true"))
}
Cheers,
Paul as well :)
Gatling Team

Related

Scala akka SSE future support

I am following this article https://doc.akka.io/docs/akka-http/current/common/sse-support.html.
Now I have a function some_def(key:String) that returns Future[Either[Throwable,T]] the payload for my SSE data
Below codebase I tried
(path("events") & get) {
complete {
Source fromFuture (some_def(key:String)) flatMapConcat {
case Right(s: T) =>
Source.tick(2.seconds, 2.second, NotUsed) map { _ =>
s
}
case _ => Source.empty
} map { s =>
ServerSentEvent(
s.message
)
} keepAlive (1.second, () => ServerSentEvent.heartbeat)
}
}
Now even though some_def(key:String) returns different payload post start SSE doesn't render that.
Is there a way we can refresh the akka - source .

mojolicious need all the time out time for load a page on production with hypnotoad

There is one page on my Mojolicious project that loads correctly but then the connections doesn't finish until arrive to the timeout time.
I got the problem only with hypnotoad on production server.
I couldn't replicate the problem on development.
I have been one day investigating the issue due the page was doing and api request to an external service.
Initially I was thinking it was due to some Mojo::UserAgent problem and I have been trying multiple combinations of Promise and IOLoop and anyone was working.
the code simplified is:
sub show {
my $s = shift;
my $customer = Model::Customers->new();
$customer->id( $s->session('id') );
$customer->get();
my $subscription = Model::Customers::Subscriptions->new();
$subscription->id( $s->session('id') );
$subscription->get();
my $plan = Model::Plans->new();
$plan->id( $subscription->idPlan );
$plan->get;
$s->stash(
namePlan => $plan->name,
monthDuration => $plan->monthDuration,
amount => $plan->amount,
end => $subscription->end,
status => $subscription->status,
signupDate => $customer->signupDate,
endTrial => $customer->endTrial,
diffTrial => $customer->diffTrial,
trialDays => $customer->trialDays,
startSubscription => $subscription->start,
discount => $plan->discount,
newsletter => $newsletter,
);
$s->render();
}
I don't share template code because isn't necessary.
The page and template load correctly but the browser, chrome, stay loading until arrive to the timeout. (15s default)
The reason of the problem is that I was using a reserved stash word 'status'.
The solution is change the name of the variable on stash and in the template:
$s->stash(
namePlan => $plan->name,
monthDuration => $plan->monthDuration,
amount => $plan->amount,
end => $subscription->end,
subStatus => $subscription->status,
signupDate => $customer->signupDate,
endTrial => $customer->endTrial,
diffTrial => $customer->diffTrial,
trialDays => $customer->trialDays,
startSubscription => $subscription->start,
discount => $plan->discount,
newsletter => $newsletter,
);

Being redirected to old PayPal UI incorrectly

i have integrated paypal to my ecommerce using ruby on rails but it always redirected to the old paypal UI instead of the latest UI. here is the old UI i mentioned:
here is roughly my code. once create order submit button pressed, my order controller will redirect to the encrypted paypal link.
order_controller.rb
def create
redirect_to #order.paypal_url(root_url, shipping_fees, payment_notification_url)
in my order model, the encrypted link code as below:
order.rb
def paypal_url(return_url, shipping_fees, notify_url)
encrypted = {
:cmd => "_s-xclick",
:encrypted => self.encrypt_for_paypal(return_url, shipping_fees, notify_url),
}
"https://www.paypal.com/cgi-bin/webscr?" + encrypted.to_query
end
def encrypt_for_paypal(return_url, shipping_fees, notify_url)
#def paypal_url(return_url, shipping_fees, notify_url)
values = {
:business => 'cxxx#hotmail.com',
:cmd => '_cart',
:upload => 1,
:currency_code => 'MYR',
:return => return_url,
:invoice => self.number,
:notify_url => notify_url,
:cert_id => "XXX",
}
line_items.each_with_index do |item, index|
values.merge!({
"amount_#{index+1}" => item.final_price,
"item_name_#{index+1}" => Product.where(id: item.variant.product_id).pluck(:title),
"item_number_#{index+1}" => item.variant.SKU,
"quantity_#{index+1}" => item.quantity,
"shipping_1" => shipping_fees
})
end
encrypted_paypal(values)
end
PAYPAL_CERT_PEM = File.read("#{Rails.root}/certs/paypal_cert.pem")
APP_CERT_PEM = File.read("#{Rails.root}/certs/app_cert.pem")
APP_KEY_PEM = File.read("#{Rails.root}/certs/app_key.pem")
def encrypted_paypal(values)
signed = OpenSSL::PKCS7::sign(OpenSSL::X509::Certificate.new(APP_CERT_PEM), OpenSSL::PKey::RSA.new(APP_KEY_PEM, ''), values.map { |k, v| "#{k}=#{v}" }.join("\n"), [], OpenSSL::PKCS7::BINARY)
OpenSSL::PKCS7::encrypt([OpenSSL::X509::Certificate.new(PAYPAL_CERT_PEM)], signed.to_der, OpenSSL::Cipher::Cipher::new("DES3"), OpenSSL::PKCS7::BINARY).to_s.gsub("\n", "")
end
please advise because i read somewhere i need to insert :method => POST to the link but im not sure how. many thanks

pg_search_scope: chaining scopes seems impossible

I have a search form for searching "documents", that have a small dozen of search criterions, including "entire_text", "keywords" and "description".
I'm using pg_search_scope, but I have 2 different scopes.
This is in my document.rb:
pg_search_scope :search_entire_text,
:against => :entire_text,
:using => {
:tsearch => {
:prefix => true,
:dictionary => "french"
}
}
pg_search_scope :search_keywords,
:associated_against => {
:keywords => [:keyword]
},
:using => {
:tsearch => {
:any_word => true
}
}
Each separately works fine. But I can't do this:
#resultats = Document.search_keywords(params[:ch_document][:keywords]).search_entire_text(params[:ch_document][:entire_text])
Is there any way to work around this?
Thanks
I've never used pg_search_scope but it looks like you indeed can't combine two pg_search_scope's.
What you could do is use :search_entire_text with a pg_search_scope and use the resulting id's in a Document.where([1,2,3]) that way you can use standard rails scope's for the remaining keyword searches.
Example:
# If pluck doesn't work you can also use map(&:id)
txt_res_ids = Document.search_entire_text(params[:ch_document][:entire_text]).pluck(:id)
final_results = Document.where(id: txt_res_ids).some_keyword_scope.all
It works. Here's the entire code ... if ever this could help someone :
Acte.rb (I didn't translate to english, the explanations are commented to correspond to the question above)
pg_search_scope :cherche_texte_complet, #i.e. find entire text
:against => :texte_complet,
:using => {
:tsearch => {
:prefix => true,
:dictionary => "french"
}
}
pg_search_scope :cherche_mots_clefs, #find keywords
:associated_against => {
:motclefs => [:motcle]
},
:using => {
:tsearch => {
:any_word => true
}
}
def self.cherche_date(debut, fin) #find date between
where("acte_date BETWEEN :date_debut AND :date_fin", {date_debut: debut, date_fin: fin})
end
def self.cherche_mots(mots)
if mots.present? #the if ... else is necessary, see controller.rb
cherche_mots_clefs(mots)
else
order("id DESC")
end
end
def self.ids_texte_compl(ids)
if ids.any?
where("id = any (array #{ids})")
else
where("id IS NOT NULL")
end
end
and actes_controller.rb
ids = Acte.cherche_texte_complet(params[:ch_acte][:texte_complet]).pluck(:id)
#resultats = Acte.cherche_date(params[:ch_acte][:date_debut],params[:ch_acte][:date_fin])
.ids_texte_compl(ids)
.cherche_mots(params[:ch_acte][:mots])
Thanks !
chaining works in pg_search 2.3.2 at least
SomeModel.pg_search_based_scope("abc").pg_search_based_scope("xyz")

Query that get the projects whose name 'starts with'. Project Server 2013

Attempt to obtain projects that begin with a particular word , but I get the following error: "The 'StartsWith' member cannot be used in the expression."
ProjectContext projContext = new ProjectContext(urlPWA);
projContext.Credentials = new SharePointOnlineCredentials(user,passwordSecurity);
projContext.Load(projContext.Projects, c => c.Where(p => p.Name.StartsWith(name, true, new CultureInfo("es-ES"))).IncludeWithDefaultProperties(f => f.Name, f => f.Tasks, f => f.ProjectResources, f => f.Owner.UserId, f => f.CheckedOutBy.UserId));
projContext.ExecuteQuery();
I'm not too familiar with special queries like that. But a quick workaround would probably be to get the whole collection and iterate it afterwards. Hopefully you do not have a million projects in your PWA :)
projContext.Load(projContext.Projects);
projContext.ExecuteQuery();
foreach (PublishedProject pubProj in projContext.Projects)
{
if (pubProj.Name.StartsWith("yourString") {
// Do something
}
}