-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move quick start source from doc into examples folder.
- Loading branch information
1 parent
71b9dfc
commit 0479617
Showing
5 changed files
with
116 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
cmake_minimum_required(VERSION 3.22.1) | ||
project(spider_getting_started) | ||
|
||
# Add the Spider library | ||
add_subdirectory(../../ spider EXCLUDE_FROM_ALL) | ||
|
||
# Add the tasks library | ||
add_library(tasks SHARED src/tasks.cpp src/tasks.hpp) | ||
|
||
# Link the Spider library to the tasks library | ||
target_link_libraries(tasks PRIVATE spider::spider) | ||
|
||
# Add the client | ||
add_executable(client src/client.cpp) | ||
|
||
# Link the Spider and tasks library to the client | ||
target_link_libraries(client PRIVATE spider::spider tasks) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include <iostream> | ||
#include <string> | ||
|
||
#include <spider/client/spider.hpp> | ||
|
||
#include "tasks.hpp" | ||
|
||
auto main(int argc, char const *argv[]) -> int { | ||
// Parse the storage backend URL from the command line arguments | ||
if (argc < 2) { | ||
std::cerr << "Usage: ./client <storage-backend-url>" << '\n'; | ||
return 1; | ||
} | ||
std::string storage_url{argv[1]}; | ||
if (storage_url.empty()) { | ||
std::cerr << "storage-backend-url cannot be empty." << '\n'; | ||
return 1; | ||
} | ||
|
||
// Create a driver that connects to the Spider cluster | ||
spider::Driver driver{storage_url}; | ||
|
||
// Submit the task for execution | ||
int x = 2; | ||
int y = 3; | ||
spider::Job<int> job = driver.start(&sum, x, y); | ||
|
||
// Wait for the job to complete | ||
job.wait_complete(); | ||
|
||
// Handle the job's success/failure | ||
switch (auto job_status = job.get_status()) { | ||
case spider::JobStatus::Succeeded: { | ||
auto result = job.get_result(); | ||
int expected = x + y; | ||
if (expected == result) { | ||
return 0; | ||
} else { | ||
std::cerr << "`sum` returned unexpected result. Expected: " << expected | ||
<< ". Actual: " << result << '\n'; | ||
return 1; | ||
} | ||
} | ||
case spider::JobStatus::Failed: { | ||
std::pair<std::string, std::string> error_and_fn_name = job.get_error(); | ||
std::cerr << "Job failed in function " << error_and_fn_name.second << " - " | ||
<< error_and_fn_name.first << '\n'; | ||
return 1; | ||
} | ||
default: | ||
std::cerr << "Job is in unexpected state - " | ||
<< static_cast<std::underlying_type_t<decltype(job_status)>>(job_status) | ||
<< '\n'; | ||
return 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "tasks.hpp" | ||
|
||
#include <spider/client/spider.hpp> | ||
|
||
// Task function implementation | ||
auto sum(spider::TaskContext& context, int x, int y) -> int { | ||
return x + y; | ||
} | ||
|
||
// Register the task with Spider | ||
SPIDER_REGISTER_TASK(sum); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef TASKS_HPP | ||
#define TASKS_HPP | ||
|
||
#include <spider/client/spider.hpp> | ||
|
||
// Task function prototype | ||
/** | ||
* @param context | ||
* @param x | ||
* @param y | ||
* @return The sum of x and y. | ||
*/ | ||
auto sum(spider::TaskContext& context, int x, int y) -> int; | ||
|
||
#endif // TASKS_HPP |