承接 tomwalder/polyfill-appengine-google-cloud-tasks 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tomwalder/polyfill-appengine-google-cloud-tasks

Composer 安装命令:

composer require tomwalder/polyfill-appengine-google-cloud-tasks

包简介

Allow simple usages of the old Google App Engine native PushTask and PushQueue to work on Cloud Run, other environments using the Google Cloud Tasks API

README 文档

README

Snazzy title, I know.

If you are doing this on AppEngine PHP 5.5 runtime:

use google\appengine\api\taskqueue\PushTask;
use google\appengine\api\taskqueue\PushQueue;

$task1 = new PushTask('/someUrl');
$task2 = new PushTask('/someOtherUrl');
$queue = new PushQueue();
$queue->addTasks([$task1, $task2]);

or this...

use google\appengine\api\taskqueue\PushTask;

$task1 = new PushTask('/someUrl');
$task1->add();

Then this library will allow that code to work outside of AppEngine, providing a polyfill to using the new Google Cloud Tasks API.

This is a stepping stone to upgrading to PHP 7 standard runtime, Flexible runtime - or better still, Cloud Run.

Installation & Setup

Pull in the library with Composer

composer require tomwalder/polyfill-appengine-google-cloud-tasks

You'll need to configure the location (region) where your Cloud Tasks queues are. Usually do this once in your bootstrap code.

CloudTasksQueue::initLocation('europe-west2');

Authentication

Your application will need credentials to call the Google Cloud Tasks API. This is usually handled automatically with Default Credentials, from GCP instances etc.

If you need to specify the path manually, do something like this...

putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/my/credentials.json');

Alternatively, you can configure and inject your own Google\Cloud\Tasks\V2\CloudTasksClient as follows. See Google Client Authentication for information about authenticating.

$obj_client = new CloudTasksClient([
   'keyFilePath' => '/path/to/keyfile.json'
]);
CloudTasksQueue::initClient($obj_client);

Absolute Task URLs (Cloud Run)

If you are using this library on Cloud Run, or GCP instances (i.e. outside of AppEngine), HTTP push task URLs are no longer relative.

So you will need to set the base HTTP target - all your relative task URLs will be appended to this.

CloudTasksQueue::initHttpTarget('https://my-awesome-project-hvdgury43f-ew.a.run.app');

Usage

Essentially, you can do most things using the original Google PushTask and PushQueue classes. See above for examples.

Further Information

Bulk Add

Google Cloud Tasks does not support bulk-adding, so the polyfill adds each task one after the other for you.

You may notice some increase in latency. Also, in rare cases you may get an error part way through the task enqueueing process. This will result in some, but not all, of your tasks being created.

Specify Project ID Manually

You can specify the Google Project ID manually as follows (we try and extract from the credentials):

CloudTasksQueue::initProject('my-awesome-project');

Performance

It is strongly recommended to use the gRPC and Protobuf extensions to get the best performance out of all Google APIs.

The default is REST unless the above are available. The Google Auth stack auto-detects.

Those extensions are available in the Google App Engine PHP 7 runtime and can be enabled in php.ini

Force Queues

If you want to be able to use new Queue names without worrying about creating the queues yourself, you can enable as follows:

CloudTasksQueue::ensureQueues(true);

This will check to see a Queue exists before inserting tasks, and attempt to create it.

This may increase latency and is probably not sensible for production use.

External Links

Credits

Some parts of this code borrowed from: https://github.com/GoogleCloudPlatform/appengine-php-sdk

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2020-10-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固