summaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
Diffstat (limited to 'example')
-rw-r--r--example/create-tasks.php7
-rw-r--r--example/example.php10
-rw-r--r--example/run-manual.php29
3 files changed, 41 insertions, 5 deletions
diff --git a/example/create-tasks.php b/example/create-tasks.php
index 35968a9..9afc886 100644
--- a/example/create-tasks.php
+++ b/example/create-tasks.php
@@ -1,10 +1,15 @@
<?php
+// this just adds a bunch of meaningless tasks, for testing purposees
+//
+// in a real world, you will have additional fields in your table
+// like 'job_name' and 'job_data'
+
$db = new mysqli();
if (!$db->real_connect('10.211.55.6', 'jobd', 'password', 'jobd'))
die('Failed to connect.');
-$target = 'server1';
+$target = 'server3';
$slots = ['low', 'normal', 'high'];
for ($i = 0; $i < 100; $i++) {
diff --git a/example/example.php b/example/example.php
index cc9cbd6..ca9e68c 100644
--- a/example/example.php
+++ b/example/example.php
@@ -3,12 +3,14 @@
require_once 'vendor/autoload.php';
try {
+ // connecting to jobd
$client = new jobd\Client(jobd\Client::MASTER_PORT);
+
+ // asking master to ask workers responsible for server1 to poll new jobs
+ $client->poke(['server1']);
} catch (Exception $e) {
die($e->getMessage());
}
-// $status = $client->status();
-// var_dump($status->getData());
-
-var_dump($client->poke(['server1']));
+// closing connection
+$client->close();
diff --git a/example/run-manual.php b/example/run-manual.php
new file mode 100644
index 0000000..5f9c43d
--- /dev/null
+++ b/example/run-manual.php
@@ -0,0 +1,29 @@
+<?php
+
+require_once 'vendor/autoload.php';
+
+// connecting to mysql
+$db = new mysqli();
+if (!$db->real_connect('10.211.55.6', 'jobd', 'password', 'jobd'))
+ die('Failed to connect.');
+
+// adding manual task
+$target = 'server1';
+$time = time();
+if (!$db->query("INSERT INTO jobs (target, slot, time_created, status) VALUES ('server1', 'normal', $time, 'manual')"))
+ die($db->error);
+
+$id = $db->insert_id;
+
+try {
+ // connecting to jobd
+ $client = new jobd\Client(jobd\Client::WORKER_PORT);
+
+ // launching task
+ $result = $client->runManual($id);
+
+ // printing the result
+ print_r($result->getData());
+} catch (Exception $e) {
+ die($e->getMessage());
+}