orbital 15 Posted September 22, 2015 Report Share Posted September 22, 2015 I have created a script to update a database's records and it has worked fine but now the number of records are getting so large it is taking a very long time to update. I need this script multi-threaded. It uses Aymen's http plugin and the json path parser by aymen. Total lines of code that need to be multi-threaded is 50 so it isn't a very large bot. I just need the define "Connect Amazon Reviews with Review Offers" multi-threaded as it includes the other one. The scheduler only kicks off the one define. I have a budget of $100 and the sooner the better. Here is the code without the specific keys: define Connect Amazon Reviews With Review Offers { set(#status,"Working","Global") comment("Get Amazon Reviews") plugin command("HTTP post.dll", "http set headers", "X-Knack-Application-Id", "APP ID") plugin command("HTTP post.dll", "http set headers", "X-Knack-REST-API-Key", "APP SECRET KEY") set(#get,$plugin function("HTTP post.dll", "$http get", "https://api.knackhq.com/v1/objects/object_8/records?filters=%5B%7B%22field%22%3A%22field_67%22%2C%22operator%22%3A%22is%20blank%22%2C%22value%22%3A%2255529614aabc05c57ecc2ef3%22%2C%22val_label%22%3A%22638%22%2C%22field_name%22%3A%22Review%22%7D%5D&rows_per_page=all", "", "", "", ""),"Global") set(#numRecord,0,"Global") set(#totalRecords,$plugin function("JSONpath.dll", "$JSONpath parser", #get, "$.total_records"),"Global") loop($plugin function("JSONpath.dll", "$JSONpath parser", #get, "$.total_records")) { set(#amazonReviewId,$plugin function("JSONpath.dll", "$JSONpath parser", #get, "$.records[{#numRecord}].id"),"Global") set(#matchId,$plugin function("JSONpath.dll", "$JSONpath parser", #get, "$.records[{#numRecord}].field_89"),"Global") comment("Get Review Offers") plugin command("HTTP post.dll", "http set headers", "X-Knack-Application-Id", "APP ID") plugin command("HTTP post.dll", "http set headers", "X-Knack-REST-API-Key", "APP SECRET KEY") set(#letsMatch,$plugin function("HTTP post.dll", "$http get", "https://api.knackhq.com/v1/objects/object_3/records?filters=%5B%7B%22field%22%3A%22field_84%22%2C%22operator%22%3A%22is%22%2C%22value%22%3A%22{#matchId}%22%2C%22field_name%22%3A%22Match%20Id%22%7D%5D&rows_per_page=all", "", "", "", ""),"Global") set(#isMatch,$plugin function("JSONpath.dll", "$JSONpath parser", #letsMatch, "$.total_records"),"Global") if($comparison(#isMatch,"=",1)) { then { set(#reviewOfferId,$plugin function("JSONpath.dll", "$JSONpath parser", #letsMatch, "$.records[0].id"),"Global") Update Record(#amazonReviewId, #reviewOfferId, 67, 8) plugin command("HTTP post.dll", "http clear objects") increment(#numRecord) } else { increment(#numRecord) } } } Connect Amazon Review With Product() set(#status,"Stopped","Global") } define Connect Amazon Review With Product { set(#status,"Working","Global") plugin command("HTTP post.dll", "http set headers", "X-Knack-Application-Id", "APP ID") plugin command("HTTP post.dll", "http set headers", "X-Knack-REST-API-Key", "APP SECRET KEY") comment("Get all amazon reviews that have a blank product") set(#get,$plugin function("HTTP post.dll", "$http get", "https://api.knackhq.com/v1/objects/object_8/records?filters=%5B%7B%22field%22%3A%22field_77%22%2C%22operator%22%3A%22is%20blank%22%2C%22value%22%3A%22557bf47473a7db120b8652e2%22%2C%22val_label%22%3A%22BSM-IGP%22%2C%22field_name%22%3A%22Product%22%7D%5D&rows_per_page=all", "", "", "", ""),"Global") set(#numRecord,0,"Global") set(#totalRecords,$plugin function("JSONpath.dll", "$JSONpath parser", #get, "$.total_records"),"Global") loop($plugin function("JSONpath.dll", "$JSONpath parser", #get, "$.total_records")) { set(#amazonReviewId,$plugin function("JSONpath.dll", "$JSONpath parser", #get, "$.records[{#numRecord}].id"),"Global") set(#asin,$find regular expression($plugin function("JSONpath.dll", "$JSONpath parser", #get, "$.records[{#numRecord}].field_65_raw.url"),"(?<=ASIN=).*$"),"Global") comment("Get Products") plugin command("HTTP post.dll", "http set headers", "X-Knack-Application-Id", "APP ID") plugin command("HTTP post.dll", "http set headers", "X-Knack-REST-API-Key", "APP SECRET KEY") set(#products,$plugin function("HTTP post.dll", "$http get", "https://api.knackhq.com/v1/objects/object_2/records?filters=%5B%7B%22field%22%3A%22field_87%22%2C%22operator%22%3A%22is%22%2C%22value%22%3A%22{#asin}%22%2C%22field_name%22%3A%22ASIN%22%7D%5D&rows_per_page=all", "", "", "", ""),"Global") set(#isMatch,$plugin function("JSONpath.dll", "$JSONpath parser", #products, "$.total_records"),"Global") if($comparison(#isMatch,"=",1)) { then { set(#productId,$plugin function("JSONpath.dll", "$JSONpath parser", #products, "$.records[0].id"),"Global") Update Record(#amazonReviewId, #productId, 77, 8) plugin command("HTTP post.dll", "http clear objects") increment(#numRecord) } else { increment(#numRecord) } } } set(#status,"Stopped","Global") } Thanks! Quote Link to post Share on other sites
HelloInsomnia 1103 Posted September 22, 2015 Report Share Posted September 22, 2015 You want the stuff in the loop multithreaded right? Not the whole command? Quote Link to post Share on other sites
orbital 15 Posted September 22, 2015 Author Report Share Posted September 22, 2015 You want the stuff in the loop multithreaded right? Not the whole command? Correct. The first command "Connect Amazon Reviews With Review Offers" is the one that takes the longest. The second define doesn't take as long as there are not as many records but it would be nice to have both loops multi-threaded. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.