Skip to content

Commit 07b736b

Browse files
committed
Add migration for cron container
1 parent fd4ad83 commit 07b736b

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?php
2+
3+
namespace EE\Migration;
4+
5+
use EE;
6+
use EE\Migration\Base;
7+
use http\Exception;
8+
9+
class AddCronGlobalService extends Base {
10+
11+
/** @var RevertableStepProcessor $rsp Keeps track of migration state. Reverts on error */
12+
private static $rsp;
13+
14+
public function __construct() {
15+
16+
parent::__construct();
17+
if ( $this->is_first_execution ) {
18+
$this->skip_this_migration = true;
19+
}
20+
}
21+
22+
/**
23+
* Execute global service container name update.
24+
*
25+
* @throws EE\ExitException
26+
*/
27+
public function up() {
28+
29+
if ( $this->skip_this_migration ) {
30+
EE::debug( 'Skipping add-cron-global-service migration as it is not needed.' );
31+
32+
return;
33+
}
34+
35+
EE::debug( 'Starting add-cron-global-service' );
36+
self::$rsp = new EE\RevertableStepProcessor();
37+
38+
$global_compose_file_path = EE_ROOT_DIR . '/services/docker-compose.yml';
39+
$global_compose_file_backup_path = EE_BACKUP_DIR . '/services/docker-compose.yml.backup';
40+
41+
$old_container = 'running' !== \EE_DOCKER::container_status( 'ee-cron-scheduler' );
42+
43+
/**
44+
* Backup old docker-compose file.
45+
*/
46+
self::$rsp->add_step(
47+
'backup-global-docker-compose-file',
48+
'EE\Migration\SiteContainers::backup_restore',
49+
'EE\Migration\SiteContainers::backup_restore',
50+
[ $global_compose_file_path, $global_compose_file_backup_path ],
51+
[ $global_compose_file_backup_path, $global_compose_file_path ]
52+
);
53+
54+
/**
55+
* Generate new docker-compose file.
56+
*/
57+
self::$rsp->add_step(
58+
'generate-global-docker-compose-file',
59+
'EE\Service\Utils\generate_global_docker_compose_yml',
60+
null,
61+
[ new \Symfony\Component\Filesystem\Filesystem() ],
62+
null
63+
);
64+
65+
if ( $old_container ) {
66+
/**
67+
* Start global-cron service container.
68+
*/
69+
self::$rsp->add_step(
70+
'enable-global-cron-service',
71+
'EE\Migration\GlobalContainers::global_service_up',
72+
null,
73+
[ EE_CRON_SERVICE ],
74+
[]
75+
);
76+
77+
/**
78+
* Remove ee-cron-scheduler container.
79+
*/
80+
self::$rsp->add_step(
81+
'remove-ee-cron-scheduler-container',
82+
'EE\Migration\AddCronGlobalService::remove_old_cron_container',
83+
null,
84+
[],
85+
[]
86+
);
87+
}
88+
89+
if ( ! self::$rsp->execute() ) {
90+
throw new \Exception( 'Unable run add-cron-global-service migrations.' );
91+
}
92+
}
93+
94+
/**
95+
* No need for down.
96+
*
97+
* @throws EE\ExitException
98+
*/
99+
public function down() {
100+
}
101+
102+
public static function remove_old_cron_container() {
103+
104+
if ( ! EE::exec( 'docker rm -f ee-cron-scheduler' ) ) {
105+
throw new \Exception( 'Unable to remove ee-cron-scheduler container' );
106+
}
107+
}
108+
}

0 commit comments

Comments
 (0)