{"id":19751056,"url":"https://github.com/n0nag0n/simple-job-queue","last_synced_at":"2025-04-10T04:57:26.813Z","repository":{"id":57023046,"uuid":"290018711","full_name":"n0nag0n/simple-job-queue","owner":"n0nag0n","description":"A simple library for interfacing with other job queue providers that gives you plenty of flexibility. Currently supports MySQL, SQLite, and Beanstalkd.","archived":false,"fork":false,"pushed_at":"2025-02-27T04:21:38.000Z","size":83,"stargazers_count":31,"open_issues_count":0,"forks_count":7,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-03T03:11:37.077Z","etag":null,"topics":["beanstalk","beanstalk-worker","beanstalkd","job-queue","mariadb","mysql","php","php-library","sqlite"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/n0nag0n.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-08-24T19:17:19.000Z","updated_at":"2025-03-25T08:29:50.000Z","dependencies_parsed_at":"2024-06-14T16:39:03.723Z","dependency_job_id":"4a6e5398-c791-49af-818d-fb6c7ecd8b71","html_url":"https://github.com/n0nag0n/simple-job-queue","commit_stats":{"total_commits":13,"total_committers":2,"mean_commits":6.5,"dds":"0.15384615384615385","last_synced_commit":"5e75da0b38bf4ba8c6de4c7c40fd7066fa36531e"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n0nag0n%2Fsimple-job-queue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n0nag0n%2Fsimple-job-queue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n0nag0n%2Fsimple-job-queue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n0nag0n%2Fsimple-job-queue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/n0nag0n","download_url":"https://codeload.github.com/n0nag0n/simple-job-queue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161264,"owners_count":21057554,"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":["beanstalk","beanstalk-worker","beanstalkd","job-queue","mariadb","mysql","php","php-library","sqlite"],"created_at":"2024-11-12T02:42:07.159Z","updated_at":"2025-04-10T04:57:26.787Z","avatar_url":"https://github.com/n0nag0n.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple PHP Job Queue\nI wanted/needed a simple job queue that could be used on a database, but also used with other adapters like beanstalkd/redis/etc if needed. Didn't really see a good option for a standalone job queue for a database.\n\n## Install\n```bash\ncomposer require n0nag0n/simple-job-queue\n```\n\n## Usage\n\nIn order for this to work, you need a way to add jobs to the queue and a way to process the jobs (a worker). Below are examples of how to add a job to the queue and how to process the job.\n\n### Adding a new job\n#### MySQL\n```php\n\u003c?php\n\nuse n0nag0n\\Job_Queue\n\n// default is mysql based job queue\n$Job_Queue = new Job_Queue('mysql', [\n\t'mysql' =\u003e [\n\t\t'table_name' =\u003e 'new_table_name', // default is job_queue_jobs\n\t\t'use_compression' =\u003e false // default is true to use COMPRESS() and UNCOMPRESS() for payload\n\t]\n]);\n\n$PDO = new PDO('mysql:dbname=testdb;host=127.0.0.1', 'user', 'pass');\n$Job_Queue-\u003eaddQueueConnection($PDO);\n\n$Job_Queue-\u003eselectPipeline('send_important_emails');\n$Job_Queue-\u003eaddJob(json_encode([ 'something' =\u003e 'that', 'ends' =\u003e 'up', 'a' =\u003e 'string' ]));\n```\n\n#### PostgreSQL\n```php\n\u003c?php\n\nuse n0nag0n\\Job_Queue\n\n// default is mysql based job queue\n$Job_Queue = new Job_Queue('pgsql', [\n\t'pgsql' =\u003e [\n\t\t'table_name' =\u003e 'new_table_name', // default is job_queue_jobs\n\t]\n]);\n\n$PDO = new PDO('pgsql:dbname=testdb;host=127.0.0.1', 'user', 'pass');\n$Job_Queue-\u003eaddQueueConnection($PDO);\n\n$Job_Queue-\u003eselectPipeline('send_important_emails');\n$Job_Queue-\u003eaddJob(json_encode([ 'something' =\u003e 'that', 'ends' =\u003e 'up', 'a' =\u003e 'string' ]));\n```\n\n#### SQLite3\n```php\n\u003c?php\n\nuse n0nag0n\\Job_Queue\n\n// default is mysql based job queue\n$Job_Queue = new Job_Queue('sqlite', [\n\t'sqlite' =\u003e [\n\t\t'table_name' =\u003e 'new_table_name' // default is job_queue_jobs\n\t]\n]);\n\n$PDO = new PDO('sqlite:example.db');\n$Job_Queue-\u003eaddQueueConnection($PDO);\n\n$Job_Queue-\u003eselectPipeline('send_important_emails');\n$Job_Queue-\u003eaddJob(json_encode([ 'something' =\u003e 'that', 'ends' =\u003e 'up', 'a' =\u003e 'string' ]));\n```\n\n#### Beanstalkd\n```php\n\u003c?php\n\nuse n0nag0n\\Job_Queue\n\n// default is mysql based job queue\n$Job_Queue = new Job_Queue('beanstalkd');\n\n$pheanstalk = Pheanstalk\\Pheanstalk::create('127.0.0.1');\n$Job_Queue-\u003eaddQueueConnection($pheanstalk);\n\n$Job_Queue-\u003eselectPipeline('send_important_emails');\n$Job_Queue-\u003eaddJob(json_encode([ 'something' =\u003e 'that', 'ends' =\u003e 'up', 'a' =\u003e 'string' ]));\n```\n\n### Running a worker\nSee `example_worker.php` for file or see below:\n```php\n\u003c?php\n\t$Job_Queue = new n0nag0n\\Job_Queue('mysql');\n\t$PDO = new PDO('mysql:dbname=testdb;host=127.0.0.1', 'user', 'pass');\n\t$Job_Queue-\u003eaddQueueConnection($PDO);\n\t$Job_Queue-\u003ewatchPipeline('send_important_emails');\n\twhile(true) {\n\t\t$job = $Job_Queue-\u003egetNextJobAndReserve();\n\n\t\t// adjust to whatever makes you sleep better at night (for database queues only, beanstalkd does not need this if statement)\n\t\tif(empty($job)) {\n\t\t\tusleep(500000);\n\t\t\tcontinue;\n\t\t}\n\n\t\techo \"Processing {$job['id']}\\n\";\n\t\t$payload = json_decode($job['payload'], true);\n\n\t\ttry {\n\t\t\t$result = doSomethingThatDoesSomething($payload);\n\n\t\t\tif($result === true) {\n\t\t\t\t$Job_Queue-\u003edeleteJob($job);\n\t\t\t} else {\n\t\t\t\t// this takes it out of the ready queue and puts it in another queue that can be picked up and \"kicked\" later.\n\t\t\t\t$Job_Queue-\u003eburyJob($job);\n\t\t\t}\n\t\t} catch(Exception $e) {\n\t\t\t$Job_Queue-\u003eburyJob($job);\n\t\t}\n\t}\n```\n\n### Handling long processes\nSupervisord is going to be your jam. Look up the many, many articles on how to implement this.\n\n### Testing\nPHPUnit Tests with sqlite3 examples for the time being.\n```\nvendor/bin/phpunit\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fn0nag0n%2Fsimple-job-queue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fn0nag0n%2Fsimple-job-queue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fn0nag0n%2Fsimple-job-queue/lists"}