-
Notifications
You must be signed in to change notification settings - Fork 7
Add cron as a global service #50
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
Open
sagarnasit
wants to merge
3
commits into
EasyEngine:develop
Choose a base branch
from
sagarnasit:fix/add-cron-gloabl-service
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
migrations/container/20190110064350_service-command_add_cron_global_service.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
namespace EE\Migration; | ||
|
||
use EE; | ||
use EE\Migration\Base; | ||
use http\Exception; | ||
|
||
class AddCronGlobalService extends Base { | ||
|
||
/** @var RevertableStepProcessor $rsp Keeps track of migration state. Reverts on error */ | ||
private static $rsp; | ||
|
||
public function __construct() { | ||
|
||
parent::__construct(); | ||
if ( $this->is_first_execution ) { | ||
$this->skip_this_migration = true; | ||
} | ||
} | ||
|
||
/** | ||
* Execute global service container name update. | ||
* | ||
* @throws EE\ExitException | ||
*/ | ||
public function up() { | ||
|
||
if ( $this->skip_this_migration ) { | ||
EE::debug( 'Skipping add-cron-global-service migration as it is not needed.' ); | ||
|
||
return; | ||
} | ||
|
||
EE::debug( 'Starting add-cron-global-service' ); | ||
self::$rsp = new EE\RevertableStepProcessor(); | ||
|
||
$global_compose_file_path = EE_ROOT_DIR . '/services/docker-compose.yml'; | ||
$global_compose_file_backup_path = EE_BACKUP_DIR . '/services/docker-compose.yml.backup'; | ||
|
||
$old_container = 'running' === \EE_DOCKER::container_status( 'ee-cron-scheduler' ); | ||
|
||
/** | ||
* Backup old docker-compose file. | ||
*/ | ||
self::$rsp->add_step( | ||
'backup-global-docker-compose-file', | ||
'EE\Migration\SiteContainers::backup_restore', | ||
'EE\Migration\SiteContainers::backup_restore', | ||
[ $global_compose_file_path, $global_compose_file_backup_path ], | ||
[ $global_compose_file_backup_path, $global_compose_file_path ] | ||
); | ||
|
||
/** | ||
* Generate new docker-compose file. | ||
*/ | ||
self::$rsp->add_step( | ||
'generate-global-docker-compose-file', | ||
'EE\Service\Utils\generate_global_docker_compose_yml', | ||
null, | ||
[ new \Symfony\Component\Filesystem\Filesystem() ], | ||
null | ||
); | ||
|
||
if ( $old_container ) { | ||
/** | ||
* Start global-cron service container. | ||
*/ | ||
self::$rsp->add_step( | ||
'enable-global-cron-service', | ||
'EE\Migration\GlobalContainers::global_service_up', | ||
null, | ||
[ EE_CRON_SERVICE ], | ||
[] | ||
); | ||
|
||
/** | ||
* Remove ee-cron-scheduler container. | ||
*/ | ||
self::$rsp->add_step( | ||
'remove-ee-cron-scheduler-container', | ||
'EE\Migration\AddCronGlobalService::remove_old_cron_container', | ||
null, | ||
[], | ||
[] | ||
); | ||
} | ||
|
||
if ( ! self::$rsp->execute() ) { | ||
throw new \Exception( 'Unable run add-cron-global-service migrations.' ); | ||
} | ||
} | ||
|
||
/** | ||
* No need for down. | ||
* | ||
* @throws EE\ExitException | ||
*/ | ||
public function down() { | ||
} | ||
|
||
public static function remove_old_cron_container() { | ||
|
||
if ( ! EE::exec( 'docker rm -f ee-cron-scheduler' ) ) { | ||
throw new \Exception( 'Unable to remove ee-cron-scheduler container' ); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use function:
EE_DOCKER::get_mounting_volume_array()
as in all of above to generate volumes. As the volume generation differs in Linux and macOS.For the volume
/var/run/docker.sock
- You can useskip_volume
:service-command/src/helper/service-utils.php
Lines 155 to 160 in 0013571
Once, this change is done, for Linux systems, the cron directory inside the EE_SERVICE_DIR will be a docker volume. So, you'll have to write migrations to take backup of the previous cron directory and then once volume directory get's symlinked, need to restore that data.