Skip to content

Commit

Permalink
Show 100% when import done in info/dashboard. (#4181)
Browse files Browse the repository at this point in the history
  • Loading branch information
dafeder committed May 7, 2024
1 parent abecdc3 commit 6ee0767
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
8 changes: 4 additions & 4 deletions modules/datastore/src/Form/DashboardForm.php
Expand Up @@ -469,7 +469,7 @@ protected function buildResourcesRow($dist): array {
'#file_path' => UrlHostTokenResolver::resolve($dist['source_path']),
],
],
$this->buildStatusCell($dist['fetcher_status'], $dist['fetcher_percent_done']),
$this->buildStatusCell($dist['fetcher_status']),
$this->buildStatusCell($dist['importer_status'], $dist['importer_percent_done'], $this->cleanUpError($dist['importer_error'])),
$this->buildPostImportStatusCell($status, $error),
];
Expand All @@ -482,20 +482,20 @@ protected function buildResourcesRow($dist): array {
*
* @param string $status
* Current job status.
* @param int $percentDone
* @param int|null $percentDone
* Percent done, 0-100.
* @param null|string $error
* An error message, if any.
*
* @return array
* Renderable array.
*/
protected function buildStatusCell(string $status, int $percentDone, ?string $error = NULL) {
protected function buildStatusCell(string $status, ?int $percentDone = NULL, ?string $error = NULL) {
return [
'data' => [
'#theme' => 'datastore_dashboard_status_cell',
'#status' => $status,
'#percent' => $percentDone,
'#percent' => $percentDone ?? NULL,
'#error' => $error,
],
'class' => str_replace('_', '-', $status),
Expand Down
8 changes: 6 additions & 2 deletions modules/datastore/src/Service/Info/ImportInfo.php
Expand Up @@ -152,10 +152,14 @@ private function getFileName($fileFetcher): string {
* @param \Procrastinator\Job\Job $job
* Either a FileFetcher or Importer object.
*
* @return float
* @return float|null
* Percentage.
*/
private function getPercentDone(Job $job): float {
private function getPercentDone(Job $job): ?float {
// If the job is done, but precent < 100, NULL.
if ($job->getResult()->getStatus() == Result::DONE) {
return 100;
}
$bytes = $this->getBytesProcessed($job);
$filesize = $this->getFileSize($job);
return ($filesize > 0) ? round($bytes / $filesize * 100) : 0;
Expand Down
@@ -1 +1 @@
{{ status }} (<span class="datastore-status-details">{{ error|default(percent ~ '%') }}</span>)
{{ status }} {% if percent is not null %}(<span class="datastore-status-details">{{ error|default(percent ~ '%') }}</span>){% endif %}
6 changes: 6 additions & 0 deletions tests/src/Functional/DatasetBTBTest.php
Expand Up @@ -454,6 +454,12 @@ private function datastoreImportAndQuery() {

$this->runQueues(['localize_import', 'datastore_import']);

// Assert dataset info shows 100%
$datasetInfoService = $this->container->get('dkan.common.dataset_info');
$metadata = $datasetInfoService->gather($dataset->identifier);
$dist = array_shift($metadata['latest_revision']['distributions']);
$this->assertEquals(100, $dist['fetcher_percent_done']);

$queryString = '[SELECT * FROM ' . $this->getResourceDatastoreTable($resource) . '][WHERE lon = "61.33"][ORDER BY lat DESC][LIMIT 1 OFFSET 0];';
$this->queryResource($resource, $queryString);
}
Expand Down

0 comments on commit 6ee0767

Please sign in to comment.