Runtime: reset stale Core baseline on upgrade
This commit is contained in:
1 parent
d002c528f5
commit
fca26fd066
4 files changed
+51
-7
No files matched your search
+24
-7
@@ -41,6 +41,11 @@ namespace Echoion::Plugins::ShortUrl
|
||||
{
|
||||
shortener_.reset();
|
||||
activationError_.clear();
|
||||
dormant_ = !hasExternalConfiguration(configPayload_);
|
||||
if (dormant_) {
|
||||
activationError_ = "plugin is not configured";
|
||||
return;
|
||||
}
|
||||
auto config = parseExternalConfig(configPayload_);
|
||||
if (!config) {
|
||||
activationError_ = std::move(config).error();
|
||||
@@ -56,6 +61,11 @@ namespace Echoion::Plugins::ShortUrl
|
||||
|
||||
void on_unload() override { shortener_.reset(); }
|
||||
|
||||
[[nodiscard]] bool ready() const noexcept
|
||||
{
|
||||
return dormant_ || shortener_ != nullptr;
|
||||
}
|
||||
|
||||
[[nodiscard]] Void::ShortUrl::Health health() const override
|
||||
{
|
||||
if (shortener_ != nullptr) {
|
||||
@@ -73,10 +83,16 @@ namespace Echoion::Plugins::ShortUrl
|
||||
shorten(const Void::ShortUrl::ShortenRequest& request) override
|
||||
{
|
||||
if (shortener_ == nullptr) {
|
||||
return {.error = {
|
||||
return {
|
||||
.short_url = {},
|
||||
.key = {},
|
||||
.expires_at_unix_seconds = 0,
|
||||
.error =
|
||||
{
|
||||
.code = Void::ShortUrl::ErrorCode::unavailable,
|
||||
.message = "external shortener is unavailable",
|
||||
}};
|
||||
},
|
||||
};
|
||||
}
|
||||
return shortener_->shorten(request);
|
||||
}
|
||||
@@ -86,6 +102,7 @@ namespace Echoion::Plugins::ShortUrl
|
||||
std::string configPayload_;
|
||||
std::string activationError_;
|
||||
std::unique_ptr<ExternalShortener> shortener_;
|
||||
bool dormant_ = false;
|
||||
};
|
||||
|
||||
} // namespace Echoion::Plugins::ShortUrl
|
||||
@@ -124,11 +141,11 @@ void void_plugin_configure(void* instance, const char* config)
|
||||
|
||||
int void_plugin_ready(void* instance)
|
||||
{
|
||||
const auto health =
|
||||
static_cast<Echoion::Plugins::ShortUrl::ExternalShortenerPlugin*>(
|
||||
instance)
|
||||
->health();
|
||||
return health.status == Void::ShortUrl::HealthStatus::healthy ? 0 : 1;
|
||||
return static_cast<Echoion::Plugins::ShortUrl::ExternalShortenerPlugin*>(
|
||||
instance)
|
||||
->ready()
|
||||
? 0
|
||||
: 1;
|
||||
}
|
||||
|
||||
Void::Service::IService* void_plugin_service(void* instance)
|
||||
|
||||
Reference in new issue
Block a user