Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit 194e079

Browse files
add new background_batching and background_daemon options to google cloud adapter
1 parent fb7cad8 commit 194e079

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 3.0.0 - 2017-07-25
44

55
* Bump up to superbalist/php-pubsub-google-cloud ^5.0 which allows for background daemon support
6+
* Add new background_batching and background_daemon options to Google Cloud adapter
67

78
## 2.0.5 - 2017-07-03
89

config/pubsub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
'auto_create_topics' => true,
6161
'auto_create_subscriptions' => true,
6262
'auth_cache' => null, // eg: \Google\Auth\Cache\MemoryCacheItemPool::class,
63+
'background_batching' => false,
64+
'background_daemon' => false,
6365
],
6466

6567
'http' => [

src/PubSubConnectionFactory.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,19 @@ protected function makeGoogleCloudAdapter(array $config)
124124
$clientIdentifier = array_get($config, 'client_identifier');
125125
$autoCreateTopics = array_get($config, 'auto_create_topics', true);
126126
$autoCreateSubscriptions = array_get($config, 'auto_create_subscriptions', true);
127+
$backgroundBatching = array_get($config, 'background_batching', false);
128+
$backgroundDaemon = array_get($config, 'background_daemon', false);
127129

128-
return new GoogleCloudPubSubAdapter($client, $clientIdentifier, $autoCreateTopics, $autoCreateSubscriptions);
130+
if ($backgroundDaemon) {
131+
putenv('IS_BATCH_DAEMON_RUNNING=true');
132+
}
133+
return new GoogleCloudPubSubAdapter(
134+
$client,
135+
$clientIdentifier,
136+
$autoCreateTopics,
137+
$autoCreateSubscriptions,
138+
$backgroundBatching
139+
);
129140
}
130141

131142
/**

tests/PubSubConnectionFactoryTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ public function testMakeGoogleCloudAdapter()
169169
'key_file' => 'my_key_file.json',
170170
'client_identifier' => 'blah',
171171
'auto_create_topics' => false,
172+
'background_batching' => true,
173+
'background_daemon' => false,
172174
];
173175
$adapter = $factory->make('gcloud', $config);
174176
$this->assertInstanceOf(GoogleCloudPubSubAdapter::class, $adapter);
@@ -178,6 +180,45 @@ public function testMakeGoogleCloudAdapter()
178180
$this->assertEquals('blah', $adapter->getClientIdentifier());
179181
$this->assertFalse($adapter->areTopicsAutoCreated());
180182
$this->assertTrue($adapter->areSubscriptionsAutoCreated());
183+
$this->assertTrue($adapter->isBackgroundBatchingEnabled());
184+
$this->assertFalse(getenv('IS_BATCH_DAEMON_RUNNING'));
185+
}
186+
187+
public function testMakeGoogleCloudAdapterWithBackgroundBatchingAndDaemonEnabled()
188+
{
189+
$container = Mockery::mock(Container::class);
190+
$container->shouldReceive('makeWith')
191+
->withArgs([
192+
'pubsub.gcloud.pub_sub_client',
193+
[
194+
'config' => [
195+
'projectId' => 12345,
196+
'keyFilePath' => 'my_key_file.json',
197+
],
198+
],
199+
])
200+
->andReturn(Mockery::mock(GoogleCloudPubSubClient::class));
201+
202+
$factory = new PubSubConnectionFactory($container);
203+
204+
$config = [
205+
'project_id' => '12345',
206+
'key_file' => 'my_key_file.json',
207+
'client_identifier' => 'blah',
208+
'auto_create_topics' => false,
209+
'background_batching' => true,
210+
'background_daemon' => true,
211+
];
212+
$adapter = $factory->make('gcloud', $config);
213+
$this->assertInstanceOf(GoogleCloudPubSubAdapter::class, $adapter);
214+
215+
$adapter = $factory->make('gcloud', $config); /* @var GoogleCloudPubSubAdapter $adapter */
216+
$this->assertInstanceOf(GoogleCloudPubSubAdapter::class, $adapter);
217+
$this->assertEquals('blah', $adapter->getClientIdentifier());
218+
$this->assertFalse($adapter->areTopicsAutoCreated());
219+
$this->assertTrue($adapter->areSubscriptionsAutoCreated());
220+
$this->assertTrue($adapter->isBackgroundBatchingEnabled());
221+
$this->assertEquals('true', getenv('IS_BATCH_DAEMON_RUNNING'));
181222
}
182223

183224
public function testMakeGoogleCloudAdapterWithAuthCache()

0 commit comments

Comments
 (0)