Support is online

Simple import got stalled #75798

Resolved Locked acvmultimedia opened this topic Thursday, 13 April 2023 · 21 replies
Author

We have a python script that executes in a cloud server that uploads the csv file to our site server and then, calls the frontend import of CSVI.

Sometimes, it works fine and performs the import, but it sometimes doesn't work and the import process gets "stalled". When executed through the web browser for the very same csv file, it works perfectly.

Attached you may find the log of an automatic import stalled (1126) and the log of an import triggered from my browser (1125).

In both cases the CSV file to import is the same and they happened with minutes of difference.

We have been dealing with this for 2 weeks and it's driving me crazy. Can you please help?

We are in RO CSVI 7.20 and in PHP 8.0.28.

Thanks!!

Support

Hello,

Attached you may find the log of an automatic import stalled (1126) and the log of an import triggered from my browser (1125).

I am guessing by automatic import you mean you are running a cron import. Do you see any error with cron import? The debug log attached does not show any errors but only shows that import is incomplete.

May I know which Joomla version you are using? Also any reason for using old RO CSVI 7.20.0 version instead of latest RO CSVI 8.7.0 version?

Kind regards,

Tharuna

=========================
If you use our extensions, please post a rating and a review at the Joomla! Extension Directory

Author

Hi Tharuna,
thank you very much for your reply!!

It's not a cron import. Let me try to explain:

  1. In my client computer, they publish some content in their custom python APP. This App uploads a csv file with this content. Then from this python app, they call the url to import the process.

I have asked my client for the response of the script, but he only gets the HTML response of the frontend import cronjob. So there is no "shutdown" signal from the client as they perform a CURL call as fas as I know.

We are in Joomla 3.10 and CSVI will be the replacement for our current import content system that will be in place once we update to Joomla 4.

I did not know there area a 8.7 version compatible with Joomla 3. Is it safe to use on Joomla 3?

Carlos

Support

Hello,

have asked my client for the response of the script, but he only gets the HTML response of the frontend import cronjob. So there is no "shutdown" signal from the client as they perform a CURL call as fas as I know.

Is there any error after import?

I did not know there area a 8.7 version compatible with Joomla 3. Is it safe to use on Joomla 3?

Yes RO CSVI 8.7.0 version works on both Joomla 3 and Joomla 4 installation.

Kind regards,

Tharuna

=========================
If you use our extensions, please post a rating and a review at the Joomla! Extension Directory

Support

Hello,

There is one question I have after checking your logfiles, when RO CSVI downloads a remote file it stores it in the tmp/com_csvi folder. When an import is stalled, is the file actually there?

Another thing that came to reading how your flow is, you mention that the python app uploads the file to the server and then triggers the import. If RO CSVI and the location where the Python script uploads the file is the same website, you can also set the template to load the file from the server instead of retrieving it from a remote location. In case the filename is not always the same, you can just specify the folder and RO CSVI will import all files in that folder. Perhaps that is an option to look into. This way you remove the dependency on an external file download.

Kind regards,

RolandD

=========================
If you use our extensions, please post a rating and a review at the Joomla! Extension Directory

Author

Hi Roland,
thank you very much for your replay.

When an import is stalled, is the file actually there?

Yes. It is there. But as you see in the logs attached, it just doesn't go through it.

you can also set the template to load the file from the server instead of retrieving it from a remote location. In case the filename is not always the same, you can just specify the folder and RO CSVI will import all files in that folder. Perhaps that is an option to look into. This way you remove the dependency on an external file download.

I tested this, but it made no difference. In any case, I will happily use this setting, so I will switch to this approach.

In any case, as I mentioned, it didn't help on my tests.

Anything I can do to get more information? I guess I could add some code somewhere to get more info in the logs...

Best!!

Carlos

Support

Hello Carlos,

Can you post the log of a stalled import where the file is read from server?

Anything I can do to get more information? I guess I could add some code somewhere to get more info in the logs...

Correct, we need to see where we can add some more debugging to understand what is going on. After you send me the logfile I can check where we should add this. Are you familiar with making code changes?

Kind regards,

RolandD

=========================
If you use our extensions, please post a rating and a review at the Joomla! Extension Directory

Author

Hi Roland,
attached you may find the log after changing the setting.

Best!!

Support

Hello Carlos,

That is a very clean log file. Did you see it? The import process did not even really start. Are there any server or PHP error logs? Is there anything in them that may explain this?

Is the output from the cronjob captured? If so what does that say, that should also give us some information.

Let me know.

Kind regards,

RolandD

=========================
If you use our extensions, please post a rating and a review at the Joomla! Extension Directory

Author

Hi Roland,
I know!!! There are nothing else in server logs. This server does not provided a PHP error log, just the APACHE error log, but the call in the regular access log shows a 200 code, so my guess is that there is no PHP error around.

Also, if I call another PHP script calling the frontend CRON URL from my browser, the import works with no issues.

If I could call the PHP cronjob command from my PHP script, that could also be an option it might work, but not sure if that is a possibility.

Regards,

Carlos

Support

Hey Carlos,

I am actually quite baffled that there is no more output from a process that just dies.

This server does not provided a PHP error log, just the APACHE error log, but the call in the regular access log shows a 200 code, so my guess is that there is no PHP error around.

That would be the front-end import.

What do you see when you run the CLI import? Can you run it directly from CLI yourself? How to run the CLI script is explained in the Setting up a cron job document.

Is there a way to reliably reproduce this issue with the front-end cron?

Kind regards,

RolandD

=========================
If you use our extensions, please post a rating and a review at the Joomla! Extension Directory

Author

Hi Roland,

What do you see when you run the CLI import? Can you run it directly from CLI yourself? How to run the CLI script is explained in the Setting up a cron job document.

Originally I configured it with a CLI import in a cronjob and we did not see issues with the import. But there were other issues related to the import that prevent us for using this approach. Basically we need the process to be started by this other remote server.

I know it is not ideal, but basically this approach simulates a remote post creation.

Is there a way to reliably reproduce this issue with the front-end cron?

Not from the browser. At the beginning we tried to trigger the import from the same PHP code that was called into our server with this code:

$ch = curl_init();
        $post_data = array();

        $url='https://CSVI-SITE';

        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $user_agent='Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0';
        curl_setopt($ch,CURLOPT_USERAGENT,$user_agent);
        $response=curl_exec($ch);
        curl_close($ch);

This was when our problems started and now we do a 2 steps approach triggering the frontend import from the external server just after the csv upload, with the same results.

Support

Hello Carlos,

But there were other issues related to the import that prevent us for using this approach.

Would you mind sharing those? The import template can be configured to use a folder for import, when no file is found, nothing is done. This way you can run the cronjob quite often, let's say every 5 minutes as it is very shortlived anyway.

Nevertheless the front-end import should also run :)

One thing I notice from the code sample is that you are doing a POST call but you can just call the front-end import as a GET, that is how the browser works. Can you give that a try and see how it goes?

Kind regards,

RolandD

=========================
If you use our extensions, please post a rating and a review at the Joomla! Extension Directory

Author

Hi Roland,
thank you very much for your understanding and following up this thread.

I have noticed that the "POST" request sometimes works, so I'm not sure if that is the cause, but to be sure, I have changed to a GET request. Let's see if that fixes the issue.

Best!!

Carlos

Support

Hello Carlos,

Looking forward to your results.

It is still strange that the process just stops without anything in any logfile because the process must have been killed. PHP doesn't stop by itself if it is still running.

Is there anything the hosting provider can see perhaps?

Kind regards,

RolandD

=========================
If you use our extensions, please post a rating and a review at the Joomla! Extension Directory

Author

Hi Roland,
after changing the command I got a different result, but not sure if it will be useful though...

Before this test I removed all the log entries and running processes from the site.

Here is what I see:

  1. The date reflected in the log file (attachment com_csvi.log.2.zip) is incorrect. It says 2023-04-17. I have attached the screenshot of the log in the listing with the correct date and time.
  2. The content reflected in the log file is actually one imported on 2023-04-17. That makes no sense because before my test I cleaned up all the logs and the csv file we read is overwritten several times every day.
  3. The actual content of the file was not imported, but immediately after I noticed this test, I checked, and I performed an import using the frontend feature and the content was correctly imported. The date in the log is wrong in any case (attachment com_csvi.log.3.zip)
  4. This has left my system with 3 running processes that I cannot relate to any of the log entries because the created tmp folders are not referred in any of the 3 log entries I have.

I hope this makes any bell sound. I'm actually disturbed by the log dates in any case and the old data trying to be imported...

Support

Hello Carlos,

Let me answer you point by point

  1. This is easily explained if you look at the log file itself. So you cleaned up all the logs but somehow the logfiles on the server were not cleaned up. So this file 2 was created on 2023-04-17 and at that time this log file had only 1 line. Notice the first log line has a date of 2023-04-17, however the second line is the date of 2023-04-19 and that is because the log writer continued there writing to this logfile. Confusing but kind of out of the ordinary, this I have seen before.
  2. The content here is of the import that was triggered by cURL and did not get past the first line. If I look at log file number 1 you posted earlier it has almost the identical output except for the timestamp. Log file 1 is from 14:01:00 and Log file 2 is from 14:01:55, UTC times. That looks like the cURL command fired twice? Is that possible?
  3. This is the same thing as with log file 2 if you check the first and second log line.
  4. The Running Processes in RO CSVI need to be removed as they are by no means correct. Since RO CSVI is a PHP application it has no idea of what is actually running on the server. The idea was nice but in practicality it is not useful as it more often than not resembles the wrong information. The only thing you can tell from there by refreshing the screen is if a process is still running. If numbers are not changing, the process is not running.

I hope this makes any bell sound.

The only thing I noticed between the logs is how often they are generated. Log 1 is at 14:01:00, Log 2 is at 14:01:55 and Log 3 is at 14:01:55 and all at the same day. So Log 2 and Log 3 are actually overlapping. Does this tell you anything about those times?

I'm actually disturbed by the log dates in any case and the old data trying to be imported...

No need to worry. To clean everything up, after deleting the logs you can go to Maintenance -> RO CSVI -> Clean temp folder, that will remove any leftover log files as well so you don't get overflow into old log files.

Kind regards,

RolandD

=========================
If you use our extensions, please post a rating and a review at the Joomla! Extension Directory

Author

Hi Roland,
thank you very much for your reply, but I'm afraid I think you need to rethink your log system. But, please let me explain my latest thoughts and focus on having a successful import.

The last test I did was trying to replicate the process from my home server and getting the curl response from teh php script.

The test is simple. I just call a PHP script from my computer command line:

 wget - "https://mysite.es/scriptfolder/test.php"

Inside the test.php file the relevant code is this:

$url = "CSVI FRONTEND CRON URL";

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$user_agent='Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0';

curl_setopt($ch,CURLOPT_USERAGENT,$user_agent);

$response=curl_exec($ch);
curl_close($ch);

print 'response=('.$response.')';exit();

This test get me the HTML code for the frontend import and then I noticed this code in the HTML:

<form method="post" action="index.php?option=com_csvi&view=imports" id="adminForm" name="adminForm">
			<h3>Template Hamaika Articles Import</h3>
			<div id="import-div">
				<div class="span2">
					<span class="badge badge-info">Processed</span>
					<div id="processed"></div>
				</div>
				<div class="span2">
					<span class="badge badge-info">Last server response</span>
					<div class="uncontrolled-interval"><span></span></div>
				</div>
			</div>
			<input type="hidden" name="task" value="" />
			<input type="hidden" name="csvi_process_id" value="1171" />
		</form>

and this JavaScript:

function startTime() {
			jQuery(".uncontrolled-interval span").everyTime(1000, 'importcounter', function(i)
			{
				if (30 > 0 && i > 30)
				{
					jQuery(this).html('The last server response has not been received in a timely fashion. The server may still be busy or stopped the process. You can wait a little longer to see if the server will sent a response or cancel the process.');
				}
				else
				{
					jQuery(this).html(i);
				}
			});
		}

So I think the problem is that your frontend import requires JavaScript to work. Am I right?

Which is a bit confusing as the PHP CLI does not need JavaScript to work... Is there a way to make this work without JavaScript?

Thanks for your help.

Carlos

PS: I promise to come back with the log issues when we fix this because the timestamps and the system is not helpful to fix issues like this.

Support

Hello Carlos,

but I'm afraid I think you need to rethink your log system.

It is not mine actually, we use the Joomla logging system. More about that later.

So I think the problem is that your frontend import requires JavaScript to work. Am I right?

Yes you are correct. I did not for a moment think about that.

Which is a bit confusing as the PHP CLI does not need JavaScript to work... Is there a way to make this work without JavaScript?

Not confusing but let me explain. A website typically has 30 seconds to load before the maximum execution time kicks in. That is because websites are not supposed to be long running processes. Users are not going to sit and wait 10-20-any number of minutes to see a webpage load. That is why you have the CLI jobs. They can run unattended for as long as they need.

What the JavaScript does is, fire the import process every time before the maximum execution time ends. This way you will not run into a timeout during the import.

Is there a way to make this work without JavaScript?

Not the front-end import as it needs the JavaScript to make sure the import runs until it is finished.

There is another idea that I have but you will need to see if this can work for you. Let me explain.

So when you call the front-end URL, the import is initialized as you have the process ID in the HTML, this part:

<input type="hidden" name="csvi_process_id" value="1171" />

If you can extract the 1171 from the output you can then call the following URL https://YOURDOMAIN/administrator/components/com_csvi/rantai/rantai.php?task=import&runId=1171. That should run for as long as the number of records is set in the template settings on the Limit tab under Lines per import. By setting this number very high it will run till the import is finished or the server kills the import :) That will all depend on how large the import files are going to be.

PS: I promise to come back with the log issues when we fix this because the timestamps and the system is not helpful to fix issues like this.

We can do that. Just need to make sure not to mix logfiles from different imports. This can happen when all the log entries in the database are removed but not the logfiles on the server. Joomla will append to existing logfiles rather than replacing them.

Looking forward to hear how you get on.

Kind regards,

RolandD

=========================
If you use our extensions, please post a rating and a review at the Joomla! Extension Directory

Author

Great!! We are getting there!!

If you can extract the 1171 from the output you can then call the following URL https://YOURDOMAIN/administrator/components/com_csvi/rantai/rantai.php?task=import&runId=1171. That should run for as long as the number of records is set in the template settings on the Limit tab under Lines per import. By setting this number very high it will run till the import is finished or the server kills the import :) That will all depend on how large the import files are going to be.

That seems something we can do using DOM parser, and limits are not an issue because it's just one line per import.

Considering other options, yesterday I was playing around with the cron CLI and I managed to make it work with this code:

include('cron.php');

Problems is that cli needs to receive a couple of parameters (key and template id) and I tried setting them before the include as this:

$template_id = '1';
$key = 'MY_KEY';
include('cron.php');

But they didn't make it through JInput in Cron, so I hardcoded them in a your cron.php file and it worked, but it's not ideal... Do you happen to know a way of passing the parameters to CLI when using "include" instead of the proper CLI? That would be a cleaner solution from my point of view...

Author

Nevermind, I have successfully used the approach you suggested and it seems to work so far.

I'll start another thread for the log issues I found.

Support

Hello Carlos,

I have successfully used the approach you suggested and it seems to work so far.

Glad to hear that.

Kind regards,

RolandD

=========================
If you use our extensions, please post a rating and a review at the Joomla! Extension Directory

This topic is locked. New replies are not possible.

Log in to reply to this topic.