Answer the question
In order to leave comments, you need to log in
How to get data from a webhook event in the correct order?
The bottom line is this - when you start the pipeline in gitlab, it gives detailed data in the webhook, the problem is that all the stages are issued randomly, and I need to save them in the correct order and receive messages about their status through the telegram bot
How can I configure the correct receipt of the stages?
My code:
if ($json = file_get_contents('php://input')) {
$print_json = print_r($json, true);
$arr = explode(',', $print_json);
for ($i = 30; $i <= 500; $i++) { // $i это номер строки в массиве json'a
if (substr($arr[$i], 1, 5) == 'stage') { // Если в строке попался stage
$stage = substr(substr($arr[$i], 9), 0, -1);
$job_name = substr(substr($arr[$i + 1], 8), 0, -1);
$status = substr(substr($arr[$i + 2], 10), 0, -1);
$finished_at = substr(substr($arr[$i + 5], 15), 0, -1);
$duration = substr(substr($arr[$i + 6], 11), 0, -1);
$first_stage = substr(substr($arr[9], 11), 0, -1); // Самый первый этап
$post = [
'chat_id' => 915597301,
'text' => $first_stage,
];
sendRequest('sendMessage', $post);
$count = 1;
for ($x = 10; $x <= 30; $x++) { // Промежуточные этапы
$intermediate_stages = substr($arr[$x], 0);
if (substr($arr[$x], -1) == ']') {
break;
}
$post = [
'chat_id' => 915597301,
'text' => substr(substr($arr[$x], 1), 0, -1),
];
sendRequest('sendMessage', $post);
$count += 1;
}
if ($count > 2) { // Последний этап
$last_stage = substr(substr($arr[$x], 1), 0, -2);
$post = [
'chat_id' => 915597301,
'text' => $last_stage,
];
sendRequest('sendMessage', $post);
}
if ($status == 'created' || $status == 'running') {
$post = [
'chat_id' => 915597301,
'text' => ' <b>Webhook caught pipeline event!</b>',
'parse_mode' => 'html'
];
sendRequest('sendMessage', $post);
} elseif ($status == 'success') {
$post = [
'chat_id' => 915597301,
'text' => ' <b>Webhook caught pipeline event!</b>',
'parse_mode' => 'html'
];
sendRequest('sendMessage', $post);
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Porridge, not code.
pool.push_back(std::thread(create_pipeline, std::ref(infiles), std::ref(outfiles), std::ref(freq)));
Why is there std::ref for infiles and outfiles. If they are constant in the function.
In a function, always mark arguments as const& except when passing primitive types and non-const or generic references. Otherwise, constant copying of data is not good.
std::thread split(std::thread(split_pipeline, std::ref(freq))); what do you want to achieve here? Why call a copy constructor? What's wrong with std::thread split(split_pipeline, std::ref(freq)); ?
Cover the std::vector and std::map types with a typedef, or make an alias.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question