Rate limit conversion from script
This commit is contained in:
+6
-3
@@ -520,11 +520,12 @@ bool loadImage(const QString &path, ImageInfoData &info, std::shared_ptr<RawImag
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConvertRunable::ConvertRunable(const QString &in, const QString &out, const QString &format, const ConvertParams ¶ms) :
|
ConvertRunable::ConvertRunable(const QString &in, const QString &out, const QString &format, const ConvertParams ¶ms, QSemaphore *semaphore) :
|
||||||
m_infile(in),
|
m_infile(in),
|
||||||
m_outfile(out),
|
m_outfile(out),
|
||||||
m_format(format),
|
m_format(format),
|
||||||
m_params(params)
|
m_params(params),
|
||||||
|
m_semaphore(semaphore)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -602,7 +603,9 @@ void writeFITSImage(fitsfile *fw, std::shared_ptr<RawImage> rawimage, ImageInfoD
|
|||||||
|
|
||||||
void ConvertRunable::run()
|
void ConvertRunable::run()
|
||||||
{
|
{
|
||||||
qDebug() << m_infile << m_outfile;
|
QSemaphoreReleaser release;
|
||||||
|
if(m_semaphore)release = QSemaphoreReleaser(m_semaphore);
|
||||||
|
|
||||||
ImageInfoData imageinfo;
|
ImageInfoData imageinfo;
|
||||||
std::shared_ptr<RawImage> rawimage;
|
std::shared_ptr<RawImage> rawimage;
|
||||||
loadImage(m_infile, imageinfo, rawimage);
|
loadImage(m_infile, imageinfo, rawimage);
|
||||||
|
|||||||
+3
-1
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <QRunnable>
|
#include <QRunnable>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QSemaphore>
|
||||||
#include "imageinfo.h"
|
#include "imageinfo.h"
|
||||||
|
|
||||||
class RawImage;
|
class RawImage;
|
||||||
@@ -35,13 +36,14 @@ public:
|
|||||||
ConvertParams(){}
|
ConvertParams(){}
|
||||||
ConvertParams(const QVariantMap &map);
|
ConvertParams(const QVariantMap &map);
|
||||||
};
|
};
|
||||||
ConvertRunable(const QString &in, const QString &out, const QString &format, const ConvertParams ¶ms = ConvertParams());
|
ConvertRunable(const QString &in, const QString &out, const QString &format, const ConvertParams ¶ms = ConvertParams(), QSemaphore *semaphore = nullptr);
|
||||||
void run() override;
|
void run() override;
|
||||||
private:
|
private:
|
||||||
QString m_infile;
|
QString m_infile;
|
||||||
QString m_outfile;
|
QString m_outfile;
|
||||||
QString m_format;
|
QString m_format;
|
||||||
ConvertParams m_params;
|
ConvertParams m_params;
|
||||||
|
QSemaphore *m_semaphore;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LOADRUNABLE_H
|
#endif // LOADRUNABLE_H
|
||||||
|
|||||||
+4
-1
@@ -17,6 +17,7 @@ ScriptEngine::ScriptEngine(QObject *parent) : QObject(parent)
|
|||||||
QJSValue engine = _jsEngine->newQObject(this);
|
QJSValue engine = _jsEngine->newQObject(this);
|
||||||
_jsEngine->globalObject().setProperty("engine", engine);
|
_jsEngine->globalObject().setProperty("engine", engine);
|
||||||
_database->init(QLatin1String("scriptengine"));
|
_database->init(QLatin1String("scriptengine"));
|
||||||
|
_semaphore.release(_pool->maxThreadCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngine::setParams(const QString &scriptPath, const QStringList &paths, const QString &outputDir)
|
void ScriptEngine::setParams(const QString &scriptPath, const QStringList &paths, const QString &outputDir)
|
||||||
@@ -79,7 +80,8 @@ bool ScriptEngine::convert(File *file, QString &outpath, QString format, QVarian
|
|||||||
|
|
||||||
info.setFile(path);
|
info.setFile(path);
|
||||||
//qDebug() << info.absolutePath() + "/" + info.completeBaseName() + "." + format.toLower();
|
//qDebug() << info.absolutePath() + "/" + info.completeBaseName() + "." + format.toLower();
|
||||||
_pool->start(new ConvertRunable(file->absoluteFilePath(), info.absolutePath() + "/" + info.completeBaseName() + "." + format.toLower(), format, params));
|
_semaphore.acquire();
|
||||||
|
_pool->start(new ConvertRunable(file->absoluteFilePath(), info.absolutePath() + "/" + info.completeBaseName() + "." + format.toLower(), format, params, &_semaphore));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,6 +111,7 @@ void ScriptEngine::run()
|
|||||||
scriptFile.close();
|
scriptFile.close();
|
||||||
QJSValue result = _jsEngine->evaluate(contents, _scriptPath);
|
QJSValue result = _jsEngine->evaluate(contents, _scriptPath);
|
||||||
qDebug() << result.isError() << result.toString();
|
qDebug() << result.isError() << result.toString();
|
||||||
|
_pool->waitForDone();
|
||||||
if(result.isError())
|
if(result.isError())
|
||||||
{
|
{
|
||||||
QString error = result.property("name").toString() + " on line " + result.property("lineNumber").toString() + " : " + result.toString();
|
QString error = result.property("name").toString() + " on line " + result.property("lineNumber").toString() + " : " + result.toString();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QThreadPool>
|
#include <QThreadPool>
|
||||||
|
#include <QSemaphore>
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
|
|
||||||
namespace Script
|
namespace Script
|
||||||
@@ -19,6 +20,7 @@ class ScriptEngine : public QObject
|
|||||||
QJSEngine *_jsEngine;
|
QJSEngine *_jsEngine;
|
||||||
Database *_database;
|
Database *_database;
|
||||||
QThreadPool *_pool;
|
QThreadPool *_pool;
|
||||||
|
QSemaphore _semaphore;
|
||||||
QString _scriptPath;
|
QString _scriptPath;
|
||||||
QString _outputDir;
|
QString _outputDir;
|
||||||
QStringList _paths;
|
QStringList _paths;
|
||||||
|
|||||||
Reference in New Issue
Block a user