Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

Commit

Permalink
Create DemoWorker for #43
Browse files Browse the repository at this point in the history
  • Loading branch information
hdsdi3g committed Apr 30, 2014
1 parent a0a54ad commit a3ae38c
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
72 changes: 72 additions & 0 deletions app/hd3gtv/mydmam/taskqueue/demo/DemoWorker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* This file is part of MyDMAM
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* Copyright (C) hdsdi3g for hd3g.tv 2014
*
*/
package hd3gtv.mydmam.taskqueue.demo;

import hd3gtv.configuration.Configuration;
import hd3gtv.mydmam.taskqueue.Broker;
import hd3gtv.mydmam.taskqueue.Job;
import hd3gtv.mydmam.taskqueue.Profile;
import hd3gtv.mydmam.taskqueue.Worker;

import java.util.ArrayList;
import java.util.List;

import org.json.simple.JSONObject;

import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;

public class DemoWorker extends Worker {

public static final Profile demo_profile = new Profile("test", "debug1");

/**
* @param duration in ms
* @return new task key
*/
public static String createTask(long duration) throws ConnectionException {
JSONObject jo = new JSONObject();
jo.put("sleep", duration);
return Broker.publishTask("Task demo", demo_profile, jo, DemoWorker.class, false, 0, null, false);
}

public void process(Job job) throws Exception {
Thread.sleep((Long) job.getContext().get("sleep"));
}

public String getShortWorkerName() {
return "debug-worker";
}

@Override
public String getLongWorkerName() {
return "Debug worker";
}

public List<Profile> getManagedProfiles() {
ArrayList<Profile> profile = new ArrayList<Profile>();
profile.add(demo_profile);
return profile;
}

public void forceStopProcess() throws Exception {
}

public boolean isConfigurationAllowToEnabled() {
return Configuration.global.getValueBoolean("service", "demo_worker");
}

}
1 change: 1 addition & 0 deletions conf/app.d-examples/service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ service:
brokercleantasks : true
administrator_mail : Me <me@domain.com>
notifications_scan: true
# demo_worker: true

javamail:
from: Me <me@domain.com>
Expand Down

0 comments on commit a3ae38c

Please sign in to comment.