60 lines
2.5 KiB
C++
60 lines
2.5 KiB
C++
#pragma once
|
|||
|
|
|
||
|
|
// Cloud Tasks v2. `parent` is projects/{p}/locations/{l}; tasks hang off a
|
||
|
|
// full queue name.
|
||
|
|
|
||
|
|
#include "google/ops/ops_product.h"
|
||
|
|
|
||
|
|
namespace molo::google::ops {
|
||
|
|
|
||
|
|
class CloudTasks : public OpsProduct {
|
||
|
|
public:
|
||
|
|
using Json = clients::body::Json;
|
||
|
|
explicit CloudTasks(std::shared_ptr<GoogleClient> c, Sleeper s = nullptr)
|
||
|
|
: OpsProduct(std::move(c), "cloudtasks", std::move(s)) {}
|
||
|
|
|
||
|
|
Json queues(const std::string& parent) const {
|
||
|
|
return list("cloudtasks.projects.locations.queues.list", at("parent", parent));
|
||
|
|
}
|
||
|
|
Json queue(const std::string& name) const {
|
||
|
|
return read("cloudtasks.projects.locations.queues.get", at("name", name));
|
||
|
|
}
|
||
|
|
Json tasks(const std::string& queue_name) const {
|
||
|
|
return list("cloudtasks.projects.locations.queues.tasks.list", at("parent", queue_name));
|
||
|
|
}
|
||
|
|
Json task(const std::string& name) const {
|
||
|
|
return read("cloudtasks.projects.locations.queues.tasks.get", at("name", name));
|
||
|
|
}
|
||
|
|
|
||
|
|
Outcome create_queue(const std::string& parent, const Json& queue, bool confirm = false) const {
|
||
|
|
return call("cloudtasks.projects.locations.queues.create", at("parent", parent).body(queue),
|
||
|
|
confirm);
|
||
|
|
}
|
||
|
|
Outcome pause_queue(const std::string& name, bool confirm = false) const {
|
||
|
|
return call("cloudtasks.projects.locations.queues.pause", at("name", name), confirm);
|
||
|
|
}
|
||
|
|
Outcome resume_queue(const std::string& name, bool confirm = false) const {
|
||
|
|
return call("cloudtasks.projects.locations.queues.resume", at("name", name), confirm);
|
||
|
|
}
|
||
|
|
Outcome create_task(const std::string& queue_name, const Json& task, bool confirm = false) const {
|
||
|
|
Args a = at("parent", queue_name);
|
||
|
|
a.field("task", task);
|
||
|
|
return call("cloudtasks.projects.locations.queues.tasks.create", a, confirm);
|
||
|
|
}
|
||
|
|
Outcome run_task(const std::string& name, bool confirm = false) const {
|
||
|
|
return call("cloudtasks.projects.locations.queues.tasks.run", at("name", name), confirm);
|
||
|
|
}
|
||
|
|
// Destructive: no default.
|
||
|
|
Outcome purge_queue(const std::string& name, bool confirm) const {
|
||
|
|
return call("cloudtasks.projects.locations.queues.purge", at("name", name), confirm);
|
||
|
|
}
|
||
|
|
Outcome delete_queue(const std::string& name, bool confirm) const {
|
||
|
|
return call("cloudtasks.projects.locations.queues.delete", at("name", name), confirm);
|
||
|
|
}
|
||
|
|
Outcome delete_task(const std::string& name, bool confirm) const {
|
||
|
|
return call("cloudtasks.projects.locations.queues.tasks.delete", at("name", name), confirm);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
} // namespace molo::google::ops
|