Better stopping.
This commit is contained in:
parent
61f3ab955c
commit
d2096c79e4
3 changed files with 12 additions and 36 deletions
|
@ -30,7 +30,7 @@ FeedDownloader::FeedDownloader(QObject *parent)
|
||||||
m_feedsUpdating(0), m_feedsTotalCount(0), m_stopUpdate(false) {
|
m_feedsUpdating(0), m_feedsTotalCount(0), m_stopUpdate(false) {
|
||||||
qRegisterMetaType<FeedDownloadResults>("FeedDownloadResults");
|
qRegisterMetaType<FeedDownloadResults>("FeedDownloadResults");
|
||||||
|
|
||||||
m_threadPool->setMaxThreadCount(6);
|
m_threadPool->setMaxThreadCount(FEED_DOWNLOADER_MAX_THREADS);
|
||||||
}
|
}
|
||||||
|
|
||||||
FeedDownloader::~FeedDownloader() {
|
FeedDownloader::~FeedDownloader() {
|
||||||
|
@ -50,10 +50,6 @@ void FeedDownloader::updateFeeds(const QList<Feed*> &feeds) {
|
||||||
|
|
||||||
qDebug().nospace() << "Starting feed updates from worker in thread: \'" << QThread::currentThreadId() << "\'.";
|
qDebug().nospace() << "Starting feed updates from worker in thread: \'" << QThread::currentThreadId() << "\'.";
|
||||||
|
|
||||||
// It may be good to disable "stop" action when batch feed update
|
|
||||||
// starts.
|
|
||||||
m_stopUpdate = false;
|
|
||||||
|
|
||||||
m_results.clear();
|
m_results.clear();
|
||||||
|
|
||||||
m_feedsUpdated = 0;
|
m_feedsUpdated = 0;
|
||||||
|
@ -65,21 +61,6 @@ void FeedDownloader::updateFeeds(const QList<Feed*> &feeds) {
|
||||||
emit updateStarted();
|
emit updateStarted();
|
||||||
|
|
||||||
for (int i = 0; i < m_feedsTotalCount; i++) {
|
for (int i = 0; i < m_feedsTotalCount; i++) {
|
||||||
if (m_stopUpdate) {
|
|
||||||
qDebug("Stopping batch feed update now.");
|
|
||||||
|
|
||||||
// We want indicate that no more feeds will be updated in this queue.
|
|
||||||
m_feedsToUpdate = 0;
|
|
||||||
|
|
||||||
if (m_feedsUpdating <= 0) {
|
|
||||||
// User forced to stop, no more feeds will start updating.
|
|
||||||
// If also no feeds are updating right now, finish.
|
|
||||||
finalizeUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
connect(feeds.at(i), &Feed::messagesObtained, this, &FeedDownloader::oneFeedUpdateFinished,
|
connect(feeds.at(i), &Feed::messagesObtained, this, &FeedDownloader::oneFeedUpdateFinished,
|
||||||
(Qt::ConnectionType) (Qt::UniqueConnection | Qt::AutoConnection));
|
(Qt::ConnectionType) (Qt::UniqueConnection | Qt::AutoConnection));
|
||||||
m_threadPool->start(feeds.at(i));
|
m_threadPool->start(feeds.at(i));
|
||||||
|
@ -91,9 +72,6 @@ void FeedDownloader::updateFeeds(const QList<Feed*> &feeds) {
|
||||||
|
|
||||||
void FeedDownloader::stopRunningUpdate() {
|
void FeedDownloader::stopRunningUpdate() {
|
||||||
m_threadPool->clear();
|
m_threadPool->clear();
|
||||||
|
|
||||||
// We want indicate that no more feeds will be updated in this queue.
|
|
||||||
m_stopUpdate = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedDownloader::oneFeedUpdateFinished(const QList<Message> &messages) {
|
void FeedDownloader::oneFeedUpdateFinished(const QList<Message> &messages) {
|
||||||
|
@ -109,22 +87,20 @@ void FeedDownloader::oneFeedUpdateFinished(const QList<Message> &messages) {
|
||||||
<< feed->id() << " in thread: \'"
|
<< feed->id() << " in thread: \'"
|
||||||
<< QThread::currentThreadId() << "\'.";
|
<< QThread::currentThreadId() << "\'.";
|
||||||
|
|
||||||
if (!m_stopUpdate) {
|
int updated_messages;
|
||||||
int updated_messages;
|
|
||||||
|
|
||||||
QMetaObject::invokeMethod(feed, "updateMessages", Qt::BlockingQueuedConnection,
|
QMetaObject::invokeMethod(feed, "updateMessages", Qt::BlockingQueuedConnection,
|
||||||
Q_RETURN_ARG(int, updated_messages),
|
Q_RETURN_ARG(int, updated_messages),
|
||||||
Q_ARG(QList<Message>, messages));
|
Q_ARG(QList<Message>, messages));
|
||||||
|
|
||||||
if (updated_messages > 0) {
|
if (updated_messages > 0) {
|
||||||
m_results.appendUpdatedFeed(QPair<QString,int>(feed->title(), updated_messages));
|
m_results.appendUpdatedFeed(QPair<QString,int>(feed->title(), updated_messages));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug("Made progress in feed updates, total feeds count %d/%d (id of feed is %d).", m_feedsUpdated, m_feedsTotalCount, feed->id());
|
qDebug("Made progress in feed updates, total feeds count %d/%d (id of feed is %d).", m_feedsUpdated, m_feedsTotalCount, feed->id());
|
||||||
emit updateProgress(feed, m_feedsUpdated, m_feedsTotalCount);
|
emit updateProgress(feed, m_feedsUpdated, m_feedsTotalCount);
|
||||||
|
|
||||||
if (m_feedsToUpdate <= 0 && m_feedsUpdating <= 0) {
|
if (m_threadPool->activeThreadCount() <= 0 || (m_feedsToUpdate <= 0 && m_feedsUpdating <= 0)) {
|
||||||
finalizeUpdate();
|
finalizeUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,10 +108,10 @@ void FeedDownloader::oneFeedUpdateFinished(const QList<Message> &messages) {
|
||||||
void FeedDownloader::finalizeUpdate() {
|
void FeedDownloader::finalizeUpdate() {
|
||||||
qDebug().nospace() << "Finished feed updates in thread: \'" << QThread::currentThreadId() << "\'.";
|
qDebug().nospace() << "Finished feed updates in thread: \'" << QThread::currentThreadId() << "\'.";
|
||||||
|
|
||||||
m_results.sort();
|
m_feedsToUpdate = 0;
|
||||||
|
m_feedsUpdating = 0;
|
||||||
|
|
||||||
// Make sure that there is not "stop" action pending.
|
m_results.sort();
|
||||||
m_stopUpdate = false;
|
|
||||||
|
|
||||||
// Update of feeds has finished.
|
// Update of feeds has finished.
|
||||||
// NOTE: This means that now "update lock" can be unlocked
|
// NOTE: This means that now "update lock" can be unlocked
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
#define DOWNLOAD_TIMEOUT 5000
|
#define DOWNLOAD_TIMEOUT 5000
|
||||||
#define MESSAGES_VIEW_DEFAULT_COL 170
|
#define MESSAGES_VIEW_DEFAULT_COL 170
|
||||||
#define FEEDS_VIEW_COLUMN_COUNT 2
|
#define FEEDS_VIEW_COLUMN_COUNT 2
|
||||||
|
#define FEED_DOWNLOADER_MAX_THREADS 6
|
||||||
#define DEFAULT_DAYS_TO_DELETE_MSG 14
|
#define DEFAULT_DAYS_TO_DELETE_MSG 14
|
||||||
#define ELLIPSIS_LENGTH 3
|
#define ELLIPSIS_LENGTH 3
|
||||||
#define MIN_CATEGORY_NAME_LENGTH 1
|
#define MIN_CATEGORY_NAME_LENGTH 1
|
||||||
|
|
|
@ -144,7 +144,6 @@ void Feed::run() {
|
||||||
<< QThread::currentThreadId() << "\'.";
|
<< QThread::currentThreadId() << "\'.";
|
||||||
|
|
||||||
QList<Message> msgs = obtainNewMessages();
|
QList<Message> msgs = obtainNewMessages();
|
||||||
|
|
||||||
emit messagesObtained(msgs);
|
emit messagesObtained(msgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue