Mercurial > hg > orthanc
changeset 2675:3fc310ceb6d4 jobs
lua callbacks for jobs
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 11 Jun 2018 20:26:24 +0200 |
parents | 373b44af938f |
children | d2f70c8f8bfd |
files | OrthancServer/LuaScripting.cpp OrthancServer/LuaScripting.h OrthancServer/OrthancRestApi/OrthancRestModalities.cpp OrthancServer/ServerContext.cpp |
diffstat | 4 files changed, 87 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/LuaScripting.cpp Mon Jun 11 16:30:13 2018 +0200 +++ b/OrthancServer/LuaScripting.cpp Mon Jun 11 20:26:24 2018 +0200 @@ -187,6 +187,64 @@ }; + class LuaScripting::JobEvent : public LuaScripting::IEvent + { + public: + enum Type + { + Type_Failure, + Type_Submitted, + Type_Success + }; + + private: + Type type_; + std::string jobId_; + + public: + JobEvent(Type type, + const std::string& jobId) : + type_(type), + jobId_(jobId) + { + } + + virtual void Apply(LuaScripting& that) + { + std::string functionName; + + switch (type_) + { + case Type_Failure: + functionName = "OnJobFailure"; + break; + + case Type_Submitted: + functionName = "OnJobSubmitted"; + break; + + case Type_Success: + functionName = "OnJobSuccess"; + break; + + default: + throw OrthancException(ErrorCode_InternalError); + } + + { + LuaScripting::Lock lock(that); + + if (lock.GetLua().IsExistingFunction(functionName.c_str())) + { + LuaFunctionCall call(lock.GetLua(), functionName.c_str()); + call.PushString(jobId_); + call.Execute(); + } + } + } + }; + + ServerContext* LuaScripting::GetServerContext(lua_State *state) { const void* value = LuaContext::GetGlobalVariable(state, "_ServerContext"); @@ -693,4 +751,22 @@ lock.GetLua().Execute(script); } } + + + void LuaScripting::SignalJobSubmitted(const std::string& jobId) + { + pendingEvents_.Enqueue(new JobEvent(JobEvent::Type_Submitted, jobId)); + } + + + void LuaScripting::SignalJobSuccess(const std::string& jobId) + { + pendingEvents_.Enqueue(new JobEvent(JobEvent::Type_Success, jobId)); + } + + + void LuaScripting::SignalJobFailure(const std::string& jobId) + { + pendingEvents_.Enqueue(new JobEvent(JobEvent::Type_Failure, jobId)); + } }
--- a/OrthancServer/LuaScripting.h Mon Jun 11 16:30:13 2018 +0200 +++ b/OrthancServer/LuaScripting.h Mon Jun 11 20:26:24 2018 +0200 @@ -58,6 +58,7 @@ class IEvent; class OnStoredInstanceEvent; class StableResourceEvent; + class JobEvent; static ServerContext* GetServerContext(lua_State *state); @@ -127,5 +128,11 @@ void Execute(const std::string& command); void LoadGlobalConfiguration(); + + void SignalJobSubmitted(const std::string& jobId); + + void SignalJobSuccess(const std::string& jobId); + + void SignalJobFailure(const std::string& jobId); }; }
--- a/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp Mon Jun 11 16:30:13 2018 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp Mon Jun 11 20:26:24 2018 +0200 @@ -702,7 +702,7 @@ ServerContext& context = OrthancRestApi::GetContext(call); - bool permissive = Toolbox::GetJsonBooleanField(request, "Permissive", true); + bool permissive = Toolbox::GetJsonBooleanField(request, "Permissive", false); bool asynchronous = Toolbox::GetJsonBooleanField(request, "Asynchronous", false); int priority = Toolbox::GetJsonIntegerField(request, "Priority", 0);
--- a/OrthancServer/ServerContext.cpp Mon Jun 11 16:30:13 2018 +0200 +++ b/OrthancServer/ServerContext.cpp Mon Jun 11 20:26:24 2018 +0200 @@ -135,24 +135,21 @@ void ServerContext::SignalJobSubmitted(const std::string& jobId) { haveJobsChanged_ = true; - - // TODO: Call Lua + lua_.SignalJobSubmitted(jobId); } void ServerContext::SignalJobSuccess(const std::string& jobId) { haveJobsChanged_ = true; - - // TODO: Call Lua + lua_.SignalJobSuccess(jobId); } void ServerContext::SignalJobFailure(const std::string& jobId) { haveJobsChanged_ = true; - - // TODO: Call Lua + lua_.SignalJobFailure(jobId); }