Skip to content
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

Closed

Conversation

edyst-tech
Copy link

No description provided.

@@ -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 \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is Rails updated?

Copy link
Author

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

Copy link
Member

@hermanzdosilovic hermanzdosilovic left a 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:

  1. Why do you need multiple callback URLs?
  2. How can we log the success of calling this URL?
  3. How can user see the status of calling this URL?
  4. 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.
  5. 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/
Copy link
Member

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.

Copy link
Author

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
Copy link
Member

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"
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted, will fix

)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces are unnecessary.

Copy link
Author

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(
Copy link
Member

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?

Copy link
Author

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)
Copy link
Member

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.

Copy link
Author

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)
Copy link
Member

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.

Copy link
Author

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: {} ] },
Copy link
Member

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?

Copy link
Author

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.

@edyst-tech
Copy link
Author

Thank you so much @hermanzdosilovic for taking your time in reviewing the pull request. We shall respond inline to your comments.

@edyst-tech
Copy link
Author

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:

  1. Why do you need multiple callback URLs?

In our use case, more than one service ought to be notified of the job result/status.

  1. How can we log the success of calling this URL?
  2. How can user see the status of calling this URL?

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.

  1. 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.

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.

  1. What data do we need to send to the callback? Can user decide what it needs?

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 >

Think about these questions and try answering them so we can iterate on this feature.

Thanks for your contribution.

Thank you @hermanzdosilovic for sharing this project!

@hermanzdosilovic
Copy link
Member

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.

@hermanzdosilovic hermanzdosilovic force-pushed the master branch 2 times, most recently from 84dafbd to f886f54 Compare January 2, 2020 00:46
@hermanzdosilovic
Copy link
Member

This feature is now part of v1.6.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants