-
Notifications
You must be signed in to change notification settings - Fork 508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add a patch to support webhooks #98
add a patch to support webhooks #98
Conversation
@@ -15,7 +15,7 @@ ENV PATH "/usr/local/ruby-2.3.3/bin:/opt/.gem/bin:$PATH" | |||
ENV GEM_HOME "/opt/.gem/" | |||
RUN echo "gem: --no-document" > /root/.gemrc && \ | |||
gem install \ | |||
rails:5.0.0 \ | |||
rails:5.1.7 \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is Rails updated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5.1.x has support for permitting arbitrary hashes.
rails/rails@e86524c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good start for #33 but we need to get back on the whiteboard for this to be closed.
I would suggest that you answer few questions:
- Why do you need multiple callback URLs?
- How can we log the success of calling this URL?
- How can user see the status of calling this URL?
- Does the call_webhooks function need to be in the
IsolateJob
or can it be in some other job so that we don't spend time on sending the data. Maybe call_webhooks can be called by some other non priority worker that just sends data to the workers. After all, we want the code to be executed as fast as possible and we want to free workers as soon as we can so they can run some other code. - What data do we need to send to the callback? Can user decide what it needs?
Think about these questions and try answering them so we can iterate on this feature.
Thanks for your contribution.
@@ -6,3 +6,4 @@ | |||
.byebug_history | |||
coverage/ | |||
judge0-api.conf | |||
.vscode/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Entries in this file should be sorted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted, will fix
@@ -0,0 +1,49 @@ | |||
about |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this file exists?
Gemfile
Outdated
@@ -26,3 +26,5 @@ group :development, :test do | |||
gem 'pry-byebug', '~> 3.4' | |||
gem 'rspec-rails', '~> 3.5' | |||
end | |||
|
|||
gem "httparty", "~> 0.17.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be added alongside with other gems. Sorted again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted, will fix
) | ||
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces are unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted, will fix
"postdata": item["postdata"], | ||
"submission": submission.to_json | ||
} | ||
response = HTTParty.post( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if this doesn't succeed? Don't we want to log that in our database somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, we definitely should. We shall start with logging errors/warnings here.
@@ -20,6 +22,7 @@ def perform(submission) | |||
write | |||
if compile == :failure | |||
clean | |||
call_webhooks(submission) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to pass submission
as an argument because it is available as member of this class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted, will fix
@@ -196,4 +201,20 @@ def strip_output(output) | |||
rescue ArgumentError | |||
return output | |||
end | |||
end | |||
|
|||
def call_webhooks(submission) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function signature could be just def call_webhooks
because submission
is available as class member.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted, will fix
@@ -71,9 +71,10 @@ def submission_params | |||
:max_processes_and_or_threads, | |||
:enable_per_process_and_thread_time_limit, | |||
:enable_per_process_and_thread_memory_limit, | |||
:max_file_size | |||
:max_file_size, | |||
{ webhooks: [ :url, postdata: {} ] }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does the user need to send postdata
? Why not just array of urls?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our use case requires passing context associated with the job here. So postdata is abstract here and can be used to pass tokens or any other job context.
Thank you so much @hermanzdosilovic for taking your time in reviewing the pull request. We shall respond inline to your comments. |
In our use case, more than one service ought to be notified of the job result/status.
In our use case, we don't use the DB records at all. If we are not notified through the webhook we treat as failure. But agree, we ought to log failures/status for debugs and for other use cases DB update with webhook status/response might be warranted.
Yeah, possible. But we felt this is simpler and faster too as we would be notified immediately on job completion. This would allow us to migrate away from the polling job we already have and avoids the delay in seeing the job result. Having another job would also mean polling or notifications for job status.
At this time we are sending the entire submission record and webhook postdata. But yes, in future we can extend this by accepting another key to specify a subset of fields to be included/filtered out in addition to < url, postData >
Thank you @hermanzdosilovic for sharing this project! |
What is the status of this PR? Do I need to create another review? Sorry for the late response, hope you are using this feature on your own instance, but I am really interested in having this in production. |
84dafbd
to
f886f54
Compare
This feature is now part of v1.6.0. |
No description provided.