http 요청에 대한 일괄 처리안녕하세요,
끝점을 모아 http 요청을 보내는 스크립트를 작성하려고 합니다.
요청 자체는 문제가 아니지만 경우에 따라 한 번에 1000개 이상의 항목(test_article)에 대한 정보를 요청해야 합니다.
한 번에 약 1000개를 요청하는 http 요청의 최대 길이에 의해 제한됩니다.
불행하게도 저는 1000개의 test_article 배치에 대한 요청을 보내고 받은 대로 연결하는 루프를 구성하는 방법을 알아낼 수 없었습니다.
어떤 통찰력이라도 대단히 감사하겠습니다
스크립팅Re: http 요청 일괄 처리안녕 라이언,
답변 해주셔서 감사합니다. 귀하의 제안을 아래 나열된 문제에 적용할 수 있는지 확인하겠습니다.
최상의,
세바스티앙Re: http 요청 일괄 처리처음 문의할 때 시작했던 스크립트를 빠뜨렸다는 것을 깨달았습니다. 명확성을 위해 여기에 항목 수가 1000개를 초과할 때 배치로 분류하는 방법을 찾고자 하는 시작점 스크립트가 있습니다.
최상의
Names Default To Here( 1 );
dt = Data Table( "test_article" ); // This is a summary data table only contains 1 column of interest 'test_article' - I want to retrieve some info for each of the unique items in that column
//If the number of items exceeds 1000, I'll need to break down the query in batches of 1000 or less to construct the http request
//Right if the list is 1000 or less, I'm golden, if it's greater, the request will fail
dt:test_article << set data type( "Numeric" );
dt << Transpose( columns( :test_article ), Output Table( "Transpose of test_article" ) );
dt = Data Table( "Transpose of test_article" );
Col_List = dt << Get Column Names( "String" );
For( i = 1, i <= N Items( Col_List ), i++,
If( Contains( Col_List[i], "Row" ),
Column( Col_List[i] ) << Set Selected( 1 )
)
);
dt << Combine Columns(
delimiter( "," ),
selected Columns only( 1 ),
Selected Columns are Indicator Columns( 0 ),
Column Name( "test_article" )
);
nc = N Cols( Data Table( "Transpose of test_article" ) );
Show( nc );
rowNum = 1;
col = Column( Data Table( "Transpose of test_article" ), "test_article" );
tableVal = col[rowNum];
adr0 = "http:/xyz:1234/oligos/more-oligo-info-intended?ids=";
address = adr0 || tableval;
request = New HTTP Request( URL( address ), Method( "GET" ), Timeout( 240 ) );
json1 = request << Send;
dt = JSON To Data Table( json1 );
Current Data Table() << set name( "test_article_info" );
Data Table( "test_article" ) << close window;
Data Table( "Transpose of test_article" ) << close window;
// I need to build a for loop that will send 1 request after the next and progressively concatenate those file together
Re: http 요청 일괄 처리정말 감사합니다! 내 문제에 대한 접근 방식을 조정하려고 노력하겠습니다.Re: http 요청 일괄 처리다음은 내가 사용하는 접근 방식입니다. JMP의 단일 인스턴스를 사용합니다. 이 코드는 HTTP 결과를 나중에 데이터 테이블로 변환되는 단일 JSON 개체로 결합합니다.
list = {};
For( i = 1, i <= number_of_iterations, i++,
request = HTTP Request(
Url( url ),
Method( "GET" ),
Headers( request_headers ),
QueryString( query ),
Password( access_token ),
Timeout( 360 )
);
data = request << Send;
If( request << IsSuccess,
response = Parse JSON( data );
If( AndMZ( Is Associative Array( response ), Contains( response, "records" ), N Items( response["records"] ) > 0 ),
list ||= response["records"]
);
,
Wait( 0.25 )
);
);Re: http 요청 일괄 처리백그라운드 http 요청에 대한 질문이 있습니다. @Craige_Hales 대답했다.
HTTP 백그라운드 요청
https://community.jmp.com/t5/Uncharted/Can-JMP-run-JMP/ba-p/283748#U283748
그런 다음 그의 코드를 가져 와서 원하는 것과 같은 작업을 수행하도록 수정했습니다.내 경우에는 다른 날짜에 대해 쿼리했지만 원하는 대로 반복되도록 코드를 수정할 수 있습니다.특정 사용 사례에 따라 약간의 조정이 필요할 수 있습니다.
도움이 되었기를 바랍니다.
url = "www....";
//Using this to generate different queries
query_keys = Associative Array();
query_keys["key1"] ="Bob"; //Or whatever your query parameters are
//I am looping over different dates
days_back = 20;
day_inc = 2;
start = Date Increment(today(),"day",-days_back);
end = Today();
cur_start = Date Increment(today(),"day",-day_inc);
cur_end = end;
index = 1;
//Here I am making files that contain the url and query key for each http request. I will use these later. This is only really needed if you intent to parallelize the http requset among multiple jmp instances.<BR />//If you don't want to parallelize the queries you can skip the writing to disk and just make a list of your query keys and/or urls.
while(cur_end>start,
query_key["startdate"] = char(Format(cur_start,"yyyy-mm-dd"));
query_key["enddate"] = char(Format(cur_end,"yyyy-mm-dd"));
Save Text File("$temp/url_file"||char(index)||".txt",url);
Save Text File("$temp/query_keys_file"||char(index)||".txt",As JSON Expr(query_keys));
index++;
if(Date Increment(cur_start,"day",-day_inc)>start,
cur_start = Date Increment(cur_start,"day",-day_inc),
cur_start = start;
);
cur_end = Date Increment(cur_end,"day",-day_inc);
);
index--;
nscripts = index;
njmp = 1; //You can parallelize this as much as you want by launching more jmp instances. Or if you want to
// a place to keep up with running instances
rp = [=> ];
rpIndex=0;
For( i = 1, i <= njmp, i += 1,
// build a custom JSL for each JMP to execute
workerFileName = Save Text File(
"$temp\deleteMe_RunsWhenLaunchedBeCareful" || Char( i ) || ".jsl",
"\[//!
deletefile("$temp/sentinel.txt");
for(i=1,i<=]\"||char(nscripts)||"\[,i++,
if(Is File("$temp/url_file"||char(i)||".txt"),
url = Load Text File( "$temp/url_file"||char(i)||".txt" ) ;
query_key = Parse JSON( Load Text File( "$temp/query_keys_file"||char(i)||".txt" ) );
Delete File("$temp/url_file"||char(i)||".txt");
Delete File("$temp/query_keys_file"||char(i)||".txt");<BR />//Using try so if one request fails I can keep moving through the requests
Try(
dig_http = New HTTP Request(URL(url),Method("Get"),Query String(query_key),Timeout(60*60*2))<<SEND></SEND>//My data is coming in as csv so I convert that to jmp.
file_name = "$temp/data"||char(i)||".csv";
Save Text File(file_name,dig_http);
dt = Open(file_name);
dt << Save("$temp/data"||char(i)||".jmp");
Delete File("$temp/data"||char(i)||".csv");
,<BR />//Dummy file if try fails
dt = New Table();
dt << Save("$temp/data"||char(i)||".jmp");
);
);
);
exit();
]\"
);
// don't launch another copy until the previous copy is running.
// JMP will become unhappy if the preferences file is busy in another
// copy of JMP. The sentinel will be deleted when JMP starts
savetextfile("$temp/sentinel.txt","");
rp[rpIndex+=1] = Run Program( executable( "jmp" ), options( {workerFileName} ) );
write("\!n",i," started...");
// wait for the sentinel to vanish
while(fileexists("$temp/sentinel.txt"),
wait(1);// don't burn the CPU while waiting
);
write("ok");
);
// many queries are probably still queued, wait for them to finish
scripts_left = nscripts;
While( scripts_left,
scripts_left = 0;
For( i = 1, i <= nscripts, i++,
If(Is File("$temp/url_file"||char(i)||".txt"),
scripts_left += 1; // count the ones still alive
)
);
write("\!n",scripts_left," http requests left");
wait(1); // don't burn the CPU while waiting
);
Write( "\!ngathering results..." );
dt = New table("Final Table");
For( i = 1, i <= nscripts, i += 1,
filename="$temp/data"||char(i)||".jmp";
// do something with the results
// clean up the temp files
tmp_dt = open(filename);
dt << Concatenate(tmp_dt,Append to First Table);
Close(tmp_dt);
deletefile(filename);
deletefile("$temp\deleteMe_RunsWhenLaunchedBeCareful" || Char( i ) || ".jsl");
);
Write( "\!ndone" );