{"action":"created","issue":{"url":"https://api.github.com/repos/SidRoberts/phalcon-cron/issues/9","repository_url":"https://api.github.com/repos/SidRoberts/phalcon-cron","labels_url":"https://api.github.com/repos/SidRoberts/phalcon-cron/issues/9/labels{/name}","comments_url":"https://api.github.com/repos/SidRoberts/phalcon-cron/issues/9/comments","events_url":"https://api.github.com/repos/SidRoberts/phalcon-cron/issues/9/events","html_url":"https://github.com/SidRoberts/phalcon-cron/issues/9","id":183100241,"number":9,"title":"Right implementation?","user":{"login":"rafaelbecks","id":3881207,"avatar_url":"https://avatars.githubusercontent.com/u/3881207?v=3","gravatar_id":"","url":"https://api.github.com/users/rafaelbecks","html_url":"https://github.com/rafaelbecks","followers_url":"https://api.github.com/users/rafaelbecks/followers","following_url":"https://api.github.com/users/rafaelbecks/following{/other_user}","gists_url":"https://api.github.com/users/rafaelbecks/gists{/gist_id}","starred_url":"https://api.github.com/users/rafaelbecks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rafaelbecks/subscriptions","organizations_url":"https://api.github.com/users/rafaelbecks/orgs","repos_url":"https://api.github.com/users/rafaelbecks/repos","events_url":"https://api.github.com/users/rafaelbecks/events{/privacy}","received_events_url":"https://api.github.com/users/rafaelbecks/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-10-14T16:58:47Z","updated_at":"2016-10-17T20:42:22Z","closed_at":null,"body":"I've been reading the docs but I can't figure out how to get the library running.\r\n\r\nI got a phalcon clit task running Ok, the idea is create a cron job to execute that task.\r\n\r\nThis is my code\r\n\r\n```\r\n $this->app->di->set(\r\n            \"cron_data_fetch\",\r\n            function () {\r\n                $cron = new \\Sid\\Phalcon\\Cron\\Manager();\r\n                 $cron->add(\r\n                    new \\Sid\\Phalcon\\Cron\\Job\\System(\r\n                        \"* 8 * * *\",\r\n                        \"php console.php mytask action\"\r\n                    )\r\n                );\r\n            });\r\n\r\n```\r\nWhat else I need to do? I also attatch the console to the DI with\r\n\r\n```\r\n$console = new \\Phalcon\\Cli\\Console();\r\n$di->setShared(\"console\", $console);\r\n```\r\n\r\nAnd I tried adding the cron this way\r\n\r\n```\r\n$cron->add(\r\n            new \\Sid\\Phalcon\\Cron\\Job\\Phalcon(\r\n                \"* 8 * * *\",\r\n                [\r\n                    \"task\"   => \"task\",\r\n                    \"action\" => \"action\",\r\n                    \"params\" => \"params\"\r\n                ]\r\n            )\r\n        );\r\n```\r\n\r\nBut it's not working\r\n\r\nThanks"},"comment":{"url":"https://api.github.com/repos/SidRoberts/phalcon-cron/issues/comments/254327608","html_url":"https://github.com/SidRoberts/phalcon-cron/issues/9#issuecomment-254327608","issue_url":"https://api.github.com/repos/SidRoberts/phalcon-cron/issues/9","id":254327608,"user":{"login":"SidRoberts","id":1364214,"avatar_url":"https://avatars.githubusercontent.com/u/1364214?v=3","gravatar_id":"","url":"https://api.github.com/users/SidRoberts","html_url":"https://github.com/SidRoberts","followers_url":"https://api.github.com/users/SidRoberts/followers","following_url":"https://api.github.com/users/SidRoberts/following{/other_user}","gists_url":"https://api.github.com/users/SidRoberts/gists{/gist_id}","starred_url":"https://api.github.com/users/SidRoberts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SidRoberts/subscriptions","organizations_url":"https://api.github.com/users/SidRoberts/orgs","repos_url":"https://api.github.com/users/SidRoberts/repos","events_url":"https://api.github.com/users/SidRoberts/events{/privacy}","received_events_url":"https://api.github.com/users/SidRoberts/received_events","type":"User","site_admin":false},"created_at":"2016-10-17T20:42:22Z","updated_at":"2016-10-17T20:42:22Z","body":"Ahh, I see. The whole point of adding it to the DI is so that you can interact with it anywhere in your application. It's not necessary. Alternatively, you could just write it in the task:\r\n\r\n```php\r\n<?php\r\n\r\nclass CronTask extends \\Phalcon\\Cli\\Task\r\n{\r\n    public function mainAction()\r\n    {\r\n        $cron = new \\Sid\\Phalcon\\Cron\\Manager();\r\n\r\n        $cron->add(\r\n            new \\Sid\\Phalcon\\Cron\\Job\\System(\r\n                \"* 8 * * *\",\r\n                \"php console.php mytask action\"\r\n            )\r\n        );\r\n\r\n        $cron->runInBackground();\r\n    }\r\n}\r\n```\r\n\r\nThe whole point of this library is to make it easier to control and maintain the crontab. Instead of changing the crontab directly, you can just write it in PHP and this will help ensure that you're development and production environments are identical.\r\n\r\nYou could also save your cron jobs in a database and be able to easily add them to the cron manager in PHP."}}
{"actor":{"display_login":"SidRoberts"}}