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.
This commit is contained in:
parent
09191ac270
commit
fcf0ef7c58
4 changed files with 25 additions and 11 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@ composer.lock
|
||||||
conf/*.yaml
|
conf/*.yaml
|
||||||
files/*.mp3
|
files/*.mp3
|
||||||
files/*.xml
|
files/*.xml
|
||||||
|
logs/*.log
|
||||||
|
|
6
README.md
Normal file
6
README.md
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
install
|
||||||
|
|
||||||
|
add cronjob to run master file
|
||||||
|
```
|
||||||
|
* * * * * cd /path/to/project && php caller.php 1>> /dev/null 2>&1
|
||||||
|
```
|
16
caller.php
16
caller.php
|
@ -3,20 +3,26 @@ require 'vendor/autoload.php';
|
||||||
require 'vendor/twilio/sdk/Services/Twilio.php';
|
require 'vendor/twilio/sdk/Services/Twilio.php';
|
||||||
|
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
$crontab = new \HybridLogic\Cron\Crontab;
|
||||||
|
|
||||||
$settings = Yaml::parse('conf/settings.yaml');
|
$settings = Yaml::parse('conf/settings.yaml');
|
||||||
|
|
||||||
$client = new Services_Twilio(
|
$client = new Services_Twilio(
|
||||||
$settings['twilio']['sid'],
|
$settings['twilio']['sid'],
|
||||||
$settings['twilio']['token']
|
$settings['twilio']['token']
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
|
$crontab->add_job(
|
||||||
|
\HybridLogic\Cron\Job::factory('test')
|
||||||
|
->on('0 10-16 * * *')
|
||||||
|
->trigger(function() use($settings, $client) {
|
||||||
$call = $client->account->calls->create(
|
$call = $client->account->calls->create(
|
||||||
$settings['application']['from'],
|
$settings['application']['from'],
|
||||||
$settings['application']['to'],
|
$settings['application']['to'],
|
||||||
$settings['application']['xml']
|
$settings['application']['xml']
|
||||||
);
|
);
|
||||||
} catch(Exception $e) {
|
})
|
||||||
echo 'Error: ' . $e->getMessage();
|
);
|
||||||
}
|
|
||||||
|
$crontab->run();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"require": {
|
"require": {
|
||||||
"twilio/sdk": "3.10.*",
|
"twilio/sdk": "3.10.*",
|
||||||
"symfony/yaml": "2.1.*"
|
"symfony/yaml": "2.1.*",
|
||||||
|
"hybridlogic/cron": "dev-master"
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue