Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev to main #383

Merged
merged 15 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .platform/schema
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4
5
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@
"drush/Commands/{$name}": [
"type:drupal-drush"
]
},
"patchLevel": {
"drupal/core": "-p2"
}
},
"repositories": [
Expand Down
308 changes: 154 additions & 154 deletions composer.lock

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions conf/cmi/search_api.index.job_listings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies:
- field.storage.node.field_organization_name
- field.storage.node.field_original_language
- field.storage.node.field_postal_area
- field.storage.node.field_postal_code
- field.storage.node.field_promoted
- field.storage.node.field_publication_starts
- field.storage.node.field_recruitment_id
Expand Down Expand Up @@ -143,6 +144,14 @@ field_settings:
dependencies:
config:
- field.storage.node.field_postal_area
field_postal_code:
label: Postinumero
datasource_id: 'entity:node'
property_path: field_postal_code
type: string
dependencies:
config:
- field.storage.node.field_postal_code
field_promoted:
label: Promoted
datasource_id: 'entity:node'
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ services:
SIMPLETEST_BASE_URL: "http://app:8888"
SIMPLETEST_DB: "mysql://drupal:drupal@db:3306/drupal"
BROWSERTEST_OUTPUT_BASE_URL: "https://${DRUPAL_HOSTNAME}"
BROWSERTEST_OUTPUT_DIRECTORY: "/app/public/sites/default/files/simpletest"
DRUPAL_VARNISH_HOST: "${COMPOSE_PROJECT_NAME}-varnish"
DRUPAL_VARNISH_PORT: 6081
REDIS_HOST: redis
Expand Down
29 changes: 16 additions & 13 deletions docker/openshift/crons/migrate-job-listings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
echo "Starting job listing migrations: $(date)"
while true
do
echo "Running job listing migrations: $(date)"
# Allow migrations to be run every 1.5 hours, reset stuck migrations every 12 hours.
drush migrate:import helfi_rekry_images:all --reset-threshold 43200 --interval 5400
drush migrate:import helfi_rekry_videos:all --reset-threshold 43200 --interval 5400
drush migrate:import helfi_rekry_task_areas:all --reset-threshold 43200 --interval 5400
drush migrate:import helfi_rekry_task_areas:all_sv --reset-threshold 43200 --interval 5400
drush migrate:import helfi_rekry_task_areas:all_en --reset-threshold 43200 --interval 5400
drush migrate:import helfi_rekry_organizations:all --update --reset-threshold 43200 --interval 5400
drush migrate:import helfi_rekry_organizations:all_sv --update --reset-threshold 43200 --interval 5400
drush migrate:import helfi_rekry_organizations:all_en --update --reset-threshold 43200 --interval 5400
drush migrate:import helfi_rekry_jobs:all --reset-threshold 43200 --interval 5400
drush migrate:import helfi_rekry_jobs:all_sv --reset-threshold 43200 --interval 5400
drush migrate:import helfi_rekry_jobs:all_en --reset-threshold 43200 --interval 5400
echo "Running job listing migrations: $(date)"
# Allow migrations to be run every 1.5 hours, reset stuck migrations every 12 hours.
drush migrate:import helfi_rekry_images:all --reset-threshold 43200 --interval 5400
drush migrate:import helfi_rekry_videos:all --reset-threshold 43200 --interval 5400
drush migrate:import helfi_rekry_task_areas:all --reset-threshold 43200 --interval 5400
drush migrate:import helfi_rekry_task_areas:all_sv --reset-threshold 43200 --interval 5400
drush migrate:import helfi_rekry_task_areas:all_en --reset-threshold 43200 --interval 5400
drush migrate:import helfi_rekry_organizations:all --update --reset-threshold 43200 --interval 5400
drush migrate:import helfi_rekry_organizations:all_sv --update --reset-threshold 43200 --interval 5400
drush migrate:import helfi_rekry_organizations:all_en --update --reset-threshold 43200 --interval 5400
drush migrate:import helfi_rekry_jobs:all --reset-threshold 43200 --interval 5400
drush migrate:import helfi_rekry_jobs:all_sv --reset-threshold 43200 --interval 5400
drush migrate:import helfi_rekry_jobs:all_en --reset-threshold 43200 --interval 5400

drush helfi-rekry-content:clean-expired-listings

# Sleep for 3 hours.
sleep 10800
done
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ dependencies:
- 'drupal:language'
- 'drupal:taxonomy'
- 'helfi_platform_config:helfi_platform_config'
- 'content_lock:content_lock'
package: HELfi
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,25 @@ services:
helfi_rekry_content.job_listing_unpublish_worker:
class: Drupal\helfi_rekry_content\Plugin\QueueWorker
arguments: ['@entity_type.manager', '@logger.channel.helfi_rekry_content']

Drupal\helfi_rekry_content\Helbit\SettingsFactory:
class: Drupal\helfi_rekry_content\Helbit\SettingsFactory
arguments:
- '@config.factory'
Drupal\helfi_rekry_content\Helbit\Settings:
class: Drupal\helfi_rekry_content\Helbit\Settings
factory:
- '@Drupal\helfi_rekry_content\Helbit\SettingsFactory'
- 'create'
Drupal\helfi_rekry_content\Helbit\HelbitClient:
class: Drupal\helfi_rekry_content\Helbit\HelbitClient
arguments:
- '@logger.channel.helfi_rekry_content'
- '@http_client'
- '@Drupal\helfi_rekry_content\Helbit\Settings'
Drupal\helfi_rekry_content\Service\JobListingCleaner:
class: Drupal\helfi_rekry_content\Service\JobListingCleaner
arguments:
- '@Drupal\helfi_rekry_content\Helbit\HelbitClient'
- '@content_lock'
- '@entity_type.manager'
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types = 1);

namespace Drupal\helfi_rekry_content\Drush\Commands;

use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\helfi_rekry_content\Service\JobListingCleaner;
use Drush\Attributes as CLI;
use Drush\Commands\DrushCommands;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* A Drush commandfile.
*/
final class JobListingCommands extends DrushCommands implements ContainerInjectionInterface {

/**
* Constructs a JobListingCommands object.
*/
public function __construct(
private readonly JobListingCleaner $jobListingCleaner,
) {
parent::__construct();
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container): self {
return new self(
$container->get(JobListingCleaner::class),
);
}

/**
* Command for removing expired job listings.
*/
#[CLI\Command(name: 'helfi-rekry-content:clean-expired-listings')]
#[CLI\Usage(name: 'helfi-rekry-content:clean-expired-listings', description: 'Remove expired job listings')]
public function cleanExpired(): void {
$count = $this->jobListingCleaner->deleteExpired();
$this->logger()->success(dt('@count job listings cleaned.', [
'@count' => $count,
]));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

declare(strict_types=1);

namespace Drupal\helfi_rekry_content\Helbit;

use Drupal\Core\Utility\Error;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Utils;
use Psr\Log\LoggerInterface;

/**
* Helbit API client.
*/
final readonly class HelbitClient {

/**
* Constructs a HelbitClient object.
*/
public function __construct(
private LoggerInterface $logger,
private ClientInterface $client,
private Settings $config,
) {
}

/**
* Get job listings.
*
* @param string $language
* Result langcode.
*
* @return array
* Job listing data.
*/
public function getJobListings(string $language): array {
try {
$response = $this->makeRequest('/open-jobs', [
'query' => [
'lang' => $this->getHelbitLangcode($language),
],
]);

if ($response['status'] === 'OK') {
return $response['jobAdvertisements'] ?? [];
}

}
catch (RequestException | GuzzleException $e) {
Error::logException($this->logger, $e);
}

return [];
}

/**
* Make request to Helbit API.
*
* @param string $endpoint
* Api endpoint.
* @param array $options
* Http client options.
*
* @return array
* Parsed response.
*
* @throws \GuzzleHttp\Exception\GuzzleException
*/
private function makeRequest(string $endpoint, array $options): array {
$options['query']['client'] = $this->config->clientId;

$response = $this->client->request('GET', "https://helbit.fi/portal-api/recruitment/v2.3$endpoint", $options);

return Utils::jsonDecode($response->getBody()->getContents(), TRUE);
}

/**
* Convert langcode to Helbit format.
*
* @param string $langcode
* Langcode.
*
* @return string
* Helbit langcode.
*/
private function getHelbitLangcode(string $langcode): string {
return match ($langcode) {
'sv' => 'sv_SE',
'en' => 'en_US',
'fi' => 'fi_FI',
};
}

}
19 changes: 19 additions & 0 deletions public/modules/custom/helfi_rekry_content/src/Helbit/Settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Drupal\helfi_rekry_content\Helbit;

/**
* DTO for Helbit client settings.
*/
final readonly class Settings {

/**
* Constructs a settings object.
*
* @param string $clientId
* Helbit client id.
*/
public function __construct(public string $clientId) {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Drupal\helfi_rekry_content\Helbit;

use Drupal\Core\Config\ConfigFactoryInterface;

/**
* Factory class for settings objects.
*/
final readonly class SettingsFactory {

/**
* Constructs a SettingsFactory object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* The config factory.
*/
public function __construct(private ConfigFactoryInterface $configFactory) {
}

/**
* Constructs a new Settings object.
*
* @return \Drupal\helfi_rekry_content\Helbit\Settings
* The helbit settings object.
*/
public function create(): Settings {
$config = $this->configFactory->get('helfi_rekry_content.settings');

return new Settings($config->get('helbit_client_id') ?: '');
}

}
Loading