Skip to content

Commit

Permalink
Merge pull request #35 from logeecom/dev
Browse files Browse the repository at this point in the history
Task execution optimizations
  • Loading branch information
yovendielmundo authored Jun 9, 2020
2 parents 435cf99 + 2a8867f commit 2e857df
Show file tree
Hide file tree
Showing 97 changed files with 2,623 additions and 860 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

## Unreleased
## [2.1.0](https://github.com/packlink-dev/ecommerce_module_core/compare/v2.0.12...v2.1.0)
** BREAKING CHANGES **

### Added
- Added a socket http client for async requests
- Added task execution priority
- Added async batch starter
- Added task runner keep alive mechanism
- Added batch task cleanup task

### Changed
- Changed when the schedules are created
- BaseDto is deprecated

## [2.0.12](https://github.com/packlink-dev/ecommerce_module_core/compare/v2.0.11...v2.0.12) - 2020-05-25
### Changed
Expand Down
67 changes: 67 additions & 0 deletions src/BusinessLogic/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,64 @@ abstract class Configuration extends \Logeecom\Infrastructure\Configuration\Conf
* Default scheduler queue name.
*/
const DEFAULT_SCHEDULER_QUEUE_NAME = 'SchedulerCheckTaskQueue';
/**
* Default task retention time expressed in days. After this time tasks are not necesseary any more in the system.
*/
const DEFAULT_MAX_TASK_AGE = 7;
/**
* Singleton instance of this class.
*
* @var static
*/
protected static $instance;

/**
* Retrieves max task age in days. Tasks older than the given number of days are no longer needed in the system.
*
* @return int Max task age in days.
*/
public function getMaxTaskAge()
{
return $this->getConfigValue('maxTaskAge', self::DEFAULT_MAX_TASK_AGE);
}

/**
* Sets max task age.
*
* @param int $maxAge Positive integer. Denotes max task age in days.
*/
public function setMaxTaskAge($maxAge)
{
$this->saveConfigValue('maxTaskAge', $maxAge);
}

/**
* Checks if any shipment has been created on Packlink.
*
* @return bool True if a shipment has been created; FALSE otherwise.
*/
public function isFirstShipmentDraftCreated()
{
$value = $this->getConfigValue('isFirstShipmentDraftCreated');

// If the value is null, that implies that the user has been registered
// before tracking of this flag has been implemented.
// For such users we will return true,
// since this flag is used to enqueue schedules if its value is false, and already registered
// users have schedules since the schedules are created when they've registered in the app.
return ($value || $value === null);
}

/**
* Sets the flag that indicates that the first shipment has been created to true.
*
* @param bool $status
*/
public function setFirstShipmentDraftCreated($status = true)
{
$this->saveConfigValue('isFirstShipmentDraftCreated', $status);
}

/**
* Returns web-hook callback URL for current system.
*
Expand Down Expand Up @@ -243,4 +294,20 @@ public function isSetupFinished()
{
return $this->getConfigValue('setupFinished') ?: false;
}

/**
* Determines whether the configuration entry is system specific.
*
* @param string $name Configuration entry name.
*
* @return bool
*/
protected function isSystemSpecific($name)
{
if ($name === 'maxTaskAge') {
return false;
}

return parent::isSystemSpecific($name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ protected function enqueueUpdateServicesTask(Configuration $configService)
// enqueue the task for updating shipping services
/** @var QueueService $queueService */
$queueService = ServiceRegister::getService(QueueService::CLASS_NAME);
$queueService->enqueue($configService->getDefaultQueueName(), new UpdateShippingServicesTask());
$task = new UpdateShippingServicesTask();
$queueService->enqueue(
$configService->getDefaultQueueName(),
$task,
$configService->getContext(),
$task->getPriority()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Packlink\BusinessLogic\Controllers\DTO;

use Packlink\BusinessLogic\DTO\BaseDto;
use Logeecom\Infrastructure\Data\DataTransferObject;
use Packlink\BusinessLogic\ShippingMethod\Models\FixedPricePolicy;
use Packlink\BusinessLogic\ShippingMethod\Models\PercentPricePolicy;
use Packlink\BusinessLogic\ShippingMethod\Models\ShippingMethod;
Expand All @@ -12,7 +12,7 @@
*
* @package Packlink\BusinessLogic\Controllers\DTO
*/
class ShippingMethodConfiguration extends BaseDto
class ShippingMethodConfiguration extends DataTransferObject
{
/**
* Shipping method identifier.
Expand Down
6 changes: 3 additions & 3 deletions src/BusinessLogic/Country/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ public static function fromArray(array $raw)
/** @var static $instance */
$instance = parent::fromArray($raw);

$instance->postalCode = static::getValue($raw, 'postal_code');
$instance->registrationLink = static::getValue($raw, 'registration_link');
$instance->platformCountry = static::getValue($raw, 'platform_country');
$instance->postalCode = static::getDataValue($raw, 'postal_code');
$instance->registrationLink = static::getDataValue($raw, 'registration_link');
$instance->platformCountry = static::getDataValue($raw, 'platform_country');

return $instance;
}
Expand Down
3 changes: 3 additions & 0 deletions src/BusinessLogic/DTO/BaseDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
* Base class for all data transfer objects.
*
* @package Packlink\BusinessLogic\Http\DTO
*
* @deprecated This class is replaced with DataTransferObject from infrastructure core. It is left behind for backwards
* compatibility.
*/
abstract class BaseDto
{
Expand Down
3 changes: 2 additions & 1 deletion src/BusinessLogic/DTO/FrontDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace Packlink\BusinessLogic\DTO;

use Logeecom\Infrastructure\Data\DataTransferObject;
use Packlink\BusinessLogic\DTO\Exceptions\FrontDtoValidationException;

/**
* Class FrontDto.
*
* @package Packlink\BusinessLogic\DTO
*/
abstract class FrontDto extends BaseDto
abstract class FrontDto extends DataTransferObject
{
/**
* Fully qualified name of this class.
Expand Down
2 changes: 1 addition & 1 deletion src/BusinessLogic/DTO/FrontDtoFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static function getFromBatch($key, array $payload)
/** @var FrontDto $className Actually, it is a string, but this is for code completion purpose. */
$className = self::$registry[$key];

return $className::fromArrayBatch($payload);
return $className::fromBatch($payload);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/BusinessLogic/Http/DTO/Analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Packlink\BusinessLogic\Http\DTO;

use Packlink\BusinessLogic\DTO\BaseDto;
use Logeecom\Infrastructure\Data\DataTransferObject;

/**
* Class Analytics.
*
* @package Packlink\BusinessLogic\Http\DTO
*/
class Analytics extends BaseDto
class Analytics extends DataTransferObject
{
const EVENT_SETUP = 'setup';
const EVENT_CONFIGURATION = 'api_configuration';
Expand Down
4 changes: 2 additions & 2 deletions src/BusinessLogic/Http/DTO/Draft.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Packlink\BusinessLogic\Http\DTO;

use Packlink\BusinessLogic\DTO\BaseDto;
use Logeecom\Infrastructure\Data\DataTransferObject;
use Packlink\BusinessLogic\Http\DTO\Draft\AdditionalData;
use Packlink\BusinessLogic\Http\DTO\Draft\Address;
use Packlink\BusinessLogic\Http\DTO\Draft\DraftPrice;
Expand All @@ -12,7 +12,7 @@
*
* @package Packlink\BusinessLogic\Http\DTO
*/
class Draft extends BaseDto
class Draft extends DataTransferObject
{
/**
* Unique user identifier.
Expand Down
4 changes: 2 additions & 2 deletions src/BusinessLogic/Http/DTO/Draft/AdditionalData.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Packlink\BusinessLogic\Http\DTO\Draft;

use Packlink\BusinessLogic\DTO\BaseDto;
use Logeecom\Infrastructure\Data\DataTransferObject;

/**
* Class AdditionalData
* @package Packlink\BusinessLogic\Http\DTO\Draft
*/
class AdditionalData extends BaseDto
class AdditionalData extends DataTransferObject
{
/**
* Value of the postal zone id corresponding to the origin postal code.
Expand Down
4 changes: 2 additions & 2 deletions src/BusinessLogic/Http/DTO/Draft/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Packlink\BusinessLogic\Http\DTO\Draft;

use Packlink\BusinessLogic\DTO\BaseDto;
use Logeecom\Infrastructure\Data\DataTransferObject;

/**
* Class Address.
*
* @package Packlink\BusinessLogic\Http\DTO\Draft
*/
class Address extends BaseDto
class Address extends DataTransferObject
{
/**
* Name of sender/receiver.
Expand Down
4 changes: 2 additions & 2 deletions src/BusinessLogic/Http/DTO/Draft/DraftItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Packlink\BusinessLogic\Http\DTO\Draft;

use Packlink\BusinessLogic\DTO\BaseDto;
use Logeecom\Infrastructure\Data\DataTransferObject;

/**
* Class DraftItem
* @package Packlink\BusinessLogic\Http\DTO\Draft
*/
class DraftItem extends BaseDto
class DraftItem extends DataTransferObject
{
/**
* Item price.
Expand Down
5 changes: 3 additions & 2 deletions src/BusinessLogic/Http/DTO/Draft/DraftPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Packlink\BusinessLogic\Http\DTO\Draft;

use Packlink\BusinessLogic\DTO\BaseDto;
use Logeecom\Infrastructure\Data\DataTransferObject;

/**
* Class DraftPrice
* @package Packlink\BusinessLogic\Http\DTO\Draft
*/
class DraftPrice extends BaseDto
class DraftPrice extends DataTransferObject
{
/**
* Value of item in EUR without taxes.
Expand All @@ -34,6 +34,7 @@ class DraftPrice extends BaseDto
* @var ItemPrice[]
*/
public $items = array();

/**
* Transforms DTO to its array format suitable for http client.
*
Expand Down
4 changes: 2 additions & 2 deletions src/BusinessLogic/Http/DTO/Draft/ItemPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Packlink\BusinessLogic\Http\DTO\Draft;

use Packlink\BusinessLogic\DTO\BaseDto;
use Logeecom\Infrastructure\Data\DataTransferObject;

/**
* Class ItemPrice
* @package Packlink\BusinessLogic\Http\DTO\Draft
*/
class ItemPrice extends BaseDto
class ItemPrice extends DataTransferObject
{
/**
* Value of item in EUR without taxes.
Expand Down
28 changes: 14 additions & 14 deletions src/BusinessLogic/Http/DTO/DropOff.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Packlink\BusinessLogic\Http\DTO;

use Packlink\BusinessLogic\DTO\BaseDto;
use Logeecom\Infrastructure\Data\DataTransferObject;

/**
* Class DropOff.
*
* @package Packlink\BusinessLogic\Http\DTO
*/
class DropOff extends BaseDto
class DropOff extends DataTransferObject
{
/**
* Unique identifier of drop-off point.
Expand Down Expand Up @@ -105,7 +105,7 @@ public function toArray()
'lat' => $this->lat,
'long' => $this->long,
'phone' => $this->phone,
'workingHours' => $this->workingHours
'workingHours' => $this->workingHours,
);
}

Expand All @@ -120,17 +120,17 @@ public static function fromArray(array $raw)
{
$entity = new self();

$entity->id = static::getValue($raw, 'id');
$entity->name = static::getValue($raw, 'commerce_name');
$entity->type = static::getValue($raw, 'type');
$entity->countryCode = static::getValue($raw, 'country');
$entity->state = static::getValue($raw, 'state');
$entity->zip = static::getValue($raw, 'zip');
$entity->city = static::getValue($raw, 'city');
$entity->address = static::getValue($raw, 'address');
$entity->lat = static::getValue($raw, 'lat', 0);
$entity->long = static::getValue($raw, 'long', 0);
$entity->phone = static::getValue($raw, 'phone');
$entity->id = static::getDataValue($raw, 'id');
$entity->name = static::getDataValue($raw, 'commerce_name');
$entity->type = static::getDataValue($raw, 'type');
$entity->countryCode = static::getDataValue($raw, 'country');
$entity->state = static::getDataValue($raw, 'state');
$entity->zip = static::getDataValue($raw, 'zip');
$entity->city = static::getDataValue($raw, 'city');
$entity->address = static::getDataValue($raw, 'address');
$entity->lat = static::getDataValue($raw, 'lat', 0);
$entity->long = static::getDataValue($raw, 'long', 0);
$entity->phone = static::getDataValue($raw, 'phone');
$entity->workingHours =
!empty($raw['opening_times']['opening_times']) ? $raw['opening_times']['opening_times'] : array();

Expand Down
Loading

0 comments on commit 2e857df

Please sign in to comment.