{"id":20012301,"url":"https://github.com/archtechx/jobpipeline","last_synced_at":"2025-05-15T14:08:38.051Z","repository":{"id":43068858,"uuid":"264239324","full_name":"archtechx/jobpipeline","owner":"archtechx","description":"Turn any series of jobs into Laravel listeners.","archived":false,"fork":false,"pushed_at":"2025-02-25T12:06:07.000Z","size":57,"stargazers_count":115,"open_issues_count":1,"forks_count":16,"subscribers_count":3,"default_branch":"2.x","last_synced_at":"2025-04-07T20:08:26.329Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/stancl/jobpipeline","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/archtechx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-15T16:08:38.000Z","updated_at":"2025-03-05T17:33:52.000Z","dependencies_parsed_at":"2024-06-18T12:40:48.014Z","dependency_job_id":"006d0e7b-b1fc-4d10-9a1a-f1f1257077ba","html_url":"https://github.com/archtechx/jobpipeline","commit_stats":{"total_commits":36,"total_committers":8,"mean_commits":4.5,"dds":"0.33333333333333337","last_synced_commit":"ebaa3fb31708e1d46e2b8b454cc779340bc0cb97"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archtechx%2Fjobpipeline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archtechx%2Fjobpipeline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archtechx%2Fjobpipeline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archtechx%2Fjobpipeline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/archtechx","download_url":"https://codeload.github.com/archtechx/jobpipeline/tar.gz/refs/heads/2.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254355335,"owners_count":22057354,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T07:29:40.267Z","updated_at":"2025-05-15T14:08:33.034Z","avatar_url":"https://github.com/archtechx.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Job Pipeline\n\n\u003cp align=\"center\"\u003e\n    \u003cimg width=\"600\" src=\"https://i.imgur.com/AcVXakZ.png\" alt=\"Job Pipeline\" /\u003e\n\u003c/p\u003e\n\nThe `JobPipeline` is a simple, yet **extremely powerful** class that lets you **convert any (series of) jobs into event listeners.**\n\nYou may use a job pipeline like any other listener, so you can register it in the `EventServiceProvider` using the `$listen` array, or in any other place using `Event::listen()` — up to you.\n\n## Creating job pipelines\n\n\u003e These code snippets will use examples from [my multi-tenancy package](https://github.com/stancl/tenancy).\n\nTo create a job pipeline, start by specifying the jobs you want to use:\n\n```php\n\u003c?php\n\nuse Stancl\\JobPipeline\\JobPipeline;\nuse Stancl\\Tenancy\\Jobs\\{CreateDatabase, MigrateDatabase, SeedDatabase};\n\nJobPipeline::make([\n    CreateDatabase::class,\n    MigrateDatabase::class,\n    SeedDatabase::class,\n])\n```\n\nThen, specify what variable you want to pass to the jobs. This will usually come from the event.\n\n```php\n\u003c?php\n\nuse Stancl\\JobPipeline\\JobPipeline;\nuse Stancl\\Tenancy\\Jobs\\{CreateDatabase, MigrateDatabase, SeedDatabase};\nuse Stancl\\Tenancy\\Events\\TenantCreated;\n\nJobPipeline::make([\n    CreateDatabase::class,\n    MigrateDatabase::class,\n    SeedDatabase::class,\n])-\u003esend(function (TenantCreated $event) {\n    return $event-\u003etenant;\n})\n```\n\nNext, decide if you want to queue the pipeline. By default, pipelines are synchronous (= not queued) by default.\n\n\u003e 🔥 If you **do** want pipelines to be queued by default, you can do that by setting a static property:\n`\\Stancl\\JobPipeline\\JobPipeline::$shouldBeQueuedByDefault = true;`\n\n```php\n\u003c?php\n\nuse Stancl\\Tenancy\\Events\\TenantCreated;\nuse Stancl\\JobPipeline\\JobPipeline;\nuse Stancl\\Tenancy\\Jobs\\{CreateDatabase, MigrateDatabase, SeedDatabase};\n\nJobPipeline::make([\n    CreateDatabase::class,\n    MigrateDatabase::class,\n    SeedDatabase::class,\n])-\u003esend(function (TenantCreated $event) {\n    return $event-\u003etenant;\n})-\u003eshouldBeQueued(true)\n```\n\nIf you wish to push the job to a different queue, you can pass a string as the second parameter:\n\n```php\n\u003c?php\n\nuse Stancl\\Tenancy\\Events\\TenantCreated;\nuse Stancl\\JobPipeline\\JobPipeline;\nuse Stancl\\Tenancy\\Jobs\\{CreateDatabase, MigrateDatabase, SeedDatabase};\n\nJobPipeline::make([\n    CreateDatabase::class,\n    MigrateDatabase::class,\n    SeedDatabase::class,\n])-\u003esend(function (TenantCreated $event) {\n    return $event-\u003etenant;\n})-\u003eshouldBeQueued(true, 'another-queue');\n```\n\nThis can be simplified by calling `shouldBeQueued(queue: 'another-queue')` since the first parameter defaults to `true`.\n\nFinally, convert the pipeline to a listener and bind it to an event:\n\n```php\n\u003c?php\n\nuse Stancl\\Tenancy\\Events\\TenantCreated;\nuse Stancl\\JobPipeline\\JobPipeline;\nuse Stancl\\Tenancy\\Jobs\\{CreateDatabase, MigrateDatabase, SeedDatabase};\nuse Illuminate\\Support\\Facades\\Event;\n\nEvent::listen(TenantCreated::class, JobPipeline::make([\n    CreateDatabase::class,\n    MigrateDatabase::class,\n    SeedDatabase::class,\n])-\u003esend(function (TenantCreated $event) {\n    return $event-\u003etenant;\n})-\u003eshouldBeQueued(true)-\u003etoListener());\n```\n\nNote that you can use job pipelines even for converting single jobs to event listeners. That's useful if you have some logic in job classes and don't want to create listener classes just to be able to run these jobs as a result of an event being fired.\n\nTip: Returning `false` from a job cancels the execution of all following jobs in the pipeline. This can be useful to cancel a job pipeline that creates, migrates, and seeds databases if the create database job exists (e.g. because it detects that a database already exists). So it can be good to separate jobs into multiple pipelines, so that each logical category of jobs can be stopped individually.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farchtechx%2Fjobpipeline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farchtechx%2Fjobpipeline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farchtechx%2Fjobpipeline/lists"}