From deaefe4d96057f812a87d923ff02dca07f304c1f Mon Sep 17 00:00:00 2001 From: BenDroid Date: Fri, 3 Nov 2017 20:12:04 +0100 Subject: [PATCH] Added configuration for cclient update status interval --- CHANGELOG.md | 2 ++ index.html | 18 ++++++++---------- src/Options.cpp | 22 ++++++++++++++++++---- src/Options.h | 2 ++ src/cc/CCClient.cpp | 4 +++- src/cc/CCClient.h | 1 - src/config.json | 3 ++- src/default_config.json | 3 ++- 8 files changed, 37 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7401b2e7..89093eae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +# v1.0.7 +- CCClient status update interval is now configurable # v1.0.6 - Fixed launch in folder containing spaces (Win) # v1.0.5 diff --git a/index.html b/index.html index 31a660a2..152f35bb 100644 --- a/index.html +++ b/index.html @@ -46,18 +46,16 @@ $(document).ready(function() { targets: -1, data: null, defaultContent: - "
" + - "" + - "" + - "" + - "" + - "" + - "" + - "
", + "" + + "" + + "" + + "" + + "" + + "", className: "center" } ], - order: [ 11, 'desc' ], + order: [ 12, 'desc' ], }); $('#clientStatusList tbody').on( 'click', 'button', function () { @@ -155,7 +153,7 @@ function round( data, type, row ) { Shares Good Shares Total Last Update - Action + Action diff --git a/src/Options.cpp b/src/Options.cpp index 0130aca3..c06c4e02 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -84,7 +84,8 @@ Options:\n" "\ --cc-url=URL url of the CC Server\n\ --cc-access-token=T access token for CC Server\n\ - --cc-worker-id=ID custom worker-id for CC Server\n" + --cc-worker-id=ID custom worker-id for CC Server\n\ + --cc-update-interval-s status update interval in seconds (default: 10 min: 1)\n" # endif # endif @@ -148,6 +149,7 @@ static struct option const options[] = { { "cc-url", 1, nullptr, 4003 }, { "cc-access-token", 1, nullptr, 4004 }, { "cc-worker-id", 1, nullptr, 4005 }, + { "cc-update-interval-s", 1, nullptr, 4012 }, { "cc-port", 1, nullptr, 4006 }, { "cc-user", 1, nullptr, 4007 }, { "cc-pass", 1, nullptr, 4008 }, @@ -200,9 +202,10 @@ static struct option const api_options[] = { static struct option const cc_client_options[] = { - { "url", 1, nullptr, 4003 }, - { "access-token", 1, nullptr, 4004 }, - { "worker-id", 1, nullptr, 4005 }, + { "url", 1, nullptr, 4003 }, + { "access-token", 1, nullptr, 4004 }, + { "worker-id", 1, nullptr, 4005 }, + { "update-interval-s", 1, nullptr, 4012 }, { 0, 0, 0, 0 } }; @@ -274,6 +277,7 @@ Options::Options(int argc, char **argv) : m_retries(5), m_retryPause(5), m_threads(0), + m_ccUpdateInterval(10), m_ccPort(0), m_affinity(-1L) { @@ -473,6 +477,7 @@ bool Options::parseArg(int key, const char *arg) free(m_ccCustomDashboard); m_ccCustomDashboard = strdup(arg); break; + case 4011: /* --daemonized */ m_daemonized = true; break; @@ -488,6 +493,8 @@ bool Options::parseArg(int key, const char *arg) return parseArg(key, strtol(arg, nullptr, 10)); case 4006: /* --cc-port */ return parseArg(key, strtol(arg, nullptr, 10)); + case 4012: /* --cc-update-interval-c */ + return parseArg(key, strtol(arg, nullptr, 10)); case 'B': /* --background */ case 'k': /* --keepalive */ @@ -627,7 +634,14 @@ bool Options::parseArg(int key, uint64_t arg) m_ccPort = (int) arg; } break; + case 4012: /* --cc-update-interval-s */ + if (arg < 1) { + showUsage(1); + return false; + } + m_ccUpdateInterval = (int) arg; + break; default: break; } diff --git a/src/Options.h b/src/Options.h index 75291d66..75051f3c 100644 --- a/src/Options.h +++ b/src/Options.h @@ -85,6 +85,7 @@ public: inline int retries() const { return m_retries; } inline int retryPause() const { return m_retryPause; } inline int threads() const { return m_threads; } + inline int ccUpdateInterval() const { return m_ccUpdateInterval; } inline int ccPort() const { return m_ccPort; } inline int64_t affinity() const { return m_affinity; } @@ -148,6 +149,7 @@ private: int m_retries; int m_retryPause; int m_threads; + int m_ccUpdateInterval; int m_ccPort; int64_t m_affinity; std::vector m_pools; diff --git a/src/cc/CCClient.cpp b/src/cc/CCClient.cpp index 2a4e0258..5880c2c8 100644 --- a/src/cc/CCClient.cpp +++ b/src/cc/CCClient.cpp @@ -74,7 +74,9 @@ CCClient::CCClient(const Options *options) } uv_timer_init(uv_default_loop(), &m_timer); - uv_timer_start(&m_timer, CCClient::onReport, kTickInterval, kTickInterval); + uv_timer_start(&m_timer, CCClient::onReport, + static_cast(m_options->ccUpdateInterval() * 1000), + static_cast(m_options->ccUpdateInterval() * 1000)); } CCClient::~CCClient() diff --git a/src/cc/CCClient.h b/src/cc/CCClient.h index 4dd70a72..6e11ac79 100644 --- a/src/cc/CCClient.h +++ b/src/cc/CCClient.h @@ -54,7 +54,6 @@ private: static void onReport(uv_timer_t *handle); static int onResponse(char* data, size_t size, size_t nmemb, std::string* responseBuffer); - constexpr static int kTickInterval = 10 * 1000; const Options *m_options; static CCClient* m_self; diff --git a/src/config.json b/src/config.json index b4d5f9db..b59e251b 100644 --- a/src/config.json +++ b/src/config.json @@ -31,6 +31,7 @@ "cc-client": { "url": "localhost:3344", // url of the CC Server (ip:port) "access-token": "mySecret", // access token for CC Server (has to be the same in config_cc.json) - "worker-id": null // custom worker-id for CC Server (otherwise hostname is used) + "worker-id": null, // custom worker-id for CC Server (otherwise hostname is used) + "update-interval-s": 10 // status update interval in seconds (default: 10 min: 1) } } diff --git a/src/default_config.json b/src/default_config.json index 8da2d984..255d2bad 100644 --- a/src/default_config.json +++ b/src/default_config.json @@ -31,6 +31,7 @@ "cc-client": { "url": "localhost:3344", // url of the CC Server (ip:port) "access-token": "mySecret", // access token for CC Server (has to be the same in config_cc.json) - "worker-id": null // custom worker-id for CC Server (otherwise hostname is used) + "worker-id": null, // custom worker-id for CC Server (otherwise hostname is used) + "update-interval-s": 10 // status update interval in seconds (default: 10 min: 1) } } \ No newline at end of file