Skip to content

Instantly share code, notes, and snippets.

@ramraj-edagutti
Last active January 14, 2019 16:56
Show Gist options
  • Select an option

  • Save ramraj-edagutti/15bb5909634a2b0de07e200295991ab9 to your computer and use it in GitHub Desktop.

Select an option

Save ramraj-edagutti/15bb5909634a2b0de07e200295991ab9 to your computer and use it in GitHub Desktop.

This is sample Java class with Gitbug markdown file

Writing the Controller Code to queue up a job on IronWorker to be done asynchronously
package collections.queue;

import java.util.LinkedList;
import java.util.List;

public class BlockingQueue {
	
	private List<Object> queue = new LinkedList<Object>();
	private int limit = 10;
	
	public BlockingQueue(int limit) {
		this.limit = limit;
	}
	
	public synchronized void enqueue(Object item) throws InterruptedException {
		if (queue.size() == limit) {
			wait();
		}
		if (queue.size() == 0){
			notifyAll();
		}
		queue.add(item);
	}
	
	public synchronized Object dequeue() throws InterruptedException {
		if (queue.size() == 0) {
			wait();
		}
		if (queue.size() == limit) {
			notifyAll();
		}
		return queue.remove(0);
	}
}
Writing the worker script to make the API request and save back to the database
setup_database

uri = URI.parse("http://pygments.appspot.com/")
request = Net::HTTP.post_form(uri, lang: params["request"]["lang"], code: params["request"]["code"])

snippet = Snippet.where(:id => params["snippet_id"]).first
snippet.update_attribute(:highlighted_code, request.body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment