{"id":794,"date":"2019-01-26T09:47:07","date_gmt":"2019-01-26T01:47:07","guid":{"rendered":"https:\/\/woohuiren.me\/blog\/?p=794"},"modified":"2019-01-26T10:39:32","modified_gmt":"2019-01-26T02:39:32","slug":"laravel-worker-on-pivotal-cloudfoundry","status":"publish","type":"post","link":"https:\/\/woohuiren.me\/blog\/laravel-worker-on-pivotal-cloudfoundry\/","title":{"rendered":"Laravel Worker On Pivotal Cloudfoundry"},"content":{"rendered":"\n<p>Laravel workers requires a separate application to be spun up as its health check type, route and commands are different from running a Laravel application served through HTTP(s). In this post, I describe considerations to take, problems that you might face and how I resolved them.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">State Management<\/h2>\n\n\n\n<p>Having a separate application process means that state has to be well managed. This is a concurrency problem. You can think of your two different applications as two different threads. States include: cache, application, queue and file. Preferably through non-file system drivers.<\/p>\n\n\n\n<p>Hence, you&#8217;ll minimally require a simple database table as your queue driver. However, it is recommended to have something better than just that &#8211; Redis. For my filesystem, I use S3 to store and share files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">User Provided Services<\/h2>\n\n\n\n<p>Application secrets are shared through <a href=\"https:\/\/docs.cloudfoundry.org\/devguide\/services\/user-provided.html\">User Provided Services<\/a>. This is to ensure the ease of secret sharing between your main Laravel application and your worker application.<\/p>\n\n\n\n<p>The following is a manifest is a Laravel worker that I would like to share with you. And I hope you&#8217;ll find it useful for your Laravel projects running on Pivotal Web Services or any other Pivotal Cloudfoundry out there.<\/p>\n\n\n\n<p class=\"has-text-color has-bright-blue-color\">worker-manifest.yml<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>---\napplications:\n- name: laravel-api-v1-worker\n  memory: 256M\n  path: .\n  services: [\n    api-redis,\n    api-db,\n    api-instagram,\n    api-pay-pal,\n    api-config,\n    api-aws,\n    api-jwt,\n    api-cache\n  ]\n  buildpack: php_buildpack\n  env:\n    CACHE_DRIVER: \"redis\"\n    QUEUE_DRIVER: \"redis\"\n    SESSION_DRIVER: \"redis\"\n    MAIL_DRIVER: \"ses\"\n    FILESYSTEM_DRIVER: \"s3\"\n  instances: 1\n  health-check-type: process\n  no-route: true\n  command: php artisan queue:work --tries=3 --daemon --memory=256<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Laravel workers requires a separate application to be spun up as its health check type, route and commands are different from running a Laravel application served through HTTP(s). In this post, I describe considerations to take, problems that you might face and how I resolved them. State Management Having a separate application process means that &hellip; <a href=\"https:\/\/woohuiren.me\/blog\/laravel-worker-on-pivotal-cloudfoundry\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Laravel Worker On Pivotal Cloudfoundry&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":795,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[2,4],"tags":[143,182,181],"class_list":["post-794","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-information-technology","category-it-softwares","tag-laravel","tag-pivotal-cloud-foundry","tag-pivotal-web-services"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/woohuiren.me\/blog\/wp-content\/uploads\/2019\/01\/Screenshot_2019-01-26-deck.png?fit=1920%2C942&ssl=1","_links":{"self":[{"href":"https:\/\/woohuiren.me\/blog\/wp-json\/wp\/v2\/posts\/794"}],"collection":[{"href":"https:\/\/woohuiren.me\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/woohuiren.me\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/woohuiren.me\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/woohuiren.me\/blog\/wp-json\/wp\/v2\/comments?post=794"}],"version-history":[{"count":7,"href":"https:\/\/woohuiren.me\/blog\/wp-json\/wp\/v2\/posts\/794\/revisions"}],"predecessor-version":[{"id":805,"href":"https:\/\/woohuiren.me\/blog\/wp-json\/wp\/v2\/posts\/794\/revisions\/805"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/woohuiren.me\/blog\/wp-json\/wp\/v2\/media\/795"}],"wp:attachment":[{"href":"https:\/\/woohuiren.me\/blog\/wp-json\/wp\/v2\/media?parent=794"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/woohuiren.me\/blog\/wp-json\/wp\/v2\/categories?post=794"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/woohuiren.me\/blog\/wp-json\/wp\/v2\/tags?post=794"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}