From fcf0ef7c58d0265139da09d8ac15c85fd9da20db Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Tue, 26 Feb 2013 17:27:12 -0500 Subject: [PATCH] Add Scheduling Capabilities Implement a scheduler based on crontab to execute calls at specific times. Using PHP-Cron, we can implement a single cron at the system level and then use methods to add cron jobs at the PHP level. This allows eventually expansion to handling multiple song calls. --- .gitignore | 1 + README.md | 6 ++++++ caller.php | 26 ++++++++++++++++---------- composer.json | 3 ++- 4 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 README.md diff --git a/.gitignore b/.gitignore index 2b3e6dc..b5aef77 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ composer.lock conf/*.yaml files/*.mp3 files/*.xml +logs/*.log diff --git a/README.md b/README.md new file mode 100644 index 0000000..2055c7a --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +install + +add cronjob to run master file +``` +* * * * * cd /path/to/project && php caller.php 1>> /dev/null 2>&1 +``` \ No newline at end of file diff --git a/caller.php b/caller.php index ebb7f90..ca12ca2 100644 --- a/caller.php +++ b/caller.php @@ -3,20 +3,26 @@ require 'vendor/autoload.php'; require 'vendor/twilio/sdk/Services/Twilio.php'; use Symfony\Component\Yaml\Yaml; +$crontab = new \HybridLogic\Cron\Crontab; $settings = Yaml::parse('conf/settings.yaml'); - $client = new Services_Twilio( $settings['twilio']['sid'], $settings['twilio']['token'] ); -try { - $call = $client->account->calls->create( - $settings['application']['from'], - $settings['application']['to'], - $settings['application']['xml'] - ); -} catch(Exception $e) { - echo 'Error: ' . $e->getMessage(); -} + + +$crontab->add_job( + \HybridLogic\Cron\Job::factory('test') + ->on('0 10-16 * * *') + ->trigger(function() use($settings, $client) { + $call = $client->account->calls->create( + $settings['application']['from'], + $settings['application']['to'], + $settings['application']['xml'] + ); + }) +); + +$crontab->run(); diff --git a/composer.json b/composer.json index 24a5ab7..12152b2 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,7 @@ { "require": { "twilio/sdk": "3.10.*", - "symfony/yaml": "2.1.*" + "symfony/yaml": "2.1.*", + "hybridlogic/cron": "dev-master" } } \ No newline at end of file