AnsweredAssumed Answered

Create or modify Job / Timer by program

Question asked by aeross on Aug 22, 2013
Latest reply on Sep 4, 2013 by frederikheremans1
Hi,

I want to create or modify a Job / Timer by program. a possible use case is a priority changement that leads dueDate change and necessarily associated Job . I tested like this :

1. I'm looking for a job  that i want to modify and modify it

// get actual Job and modifying it
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
final Date d = sdf.parse((String) processEngine .getRuntimeService().getVariable(processInstanceId, "dueDate"));
final Long expirationTime = d.getTime() - 2700000;
final Date expirationDate = new Date(expirationTime);
final StringBuilder sb = new StringBuilder("R3/");
sb.append(sdf.format(expirationDate));
sb.append("/PT15M");

final JobEntity j = (JobEntity) processEngine.getManagementService()
                                             .createJobQuery()
                                             .processInstanceId(processInstanceId)
                                             .singleResult();
final TimerEntity timer = (TimerEntity) j;
timer.setDuedate(d);
timer.setRepeat(sb.toString());



2. I test to record theses changes

Context.getCommandContext().getJobEntityManager().schedule(timer);

[indent]In this case CommandContext is  null and I don't know why. Can you light me?[/indent]



3. After looking to code "JobEntityManager.java" at line 53 and "JobEntity.java" at line 83 it test that

final Command<String> c = new Command<String>() {
                @Override
                public String execute(CommandContext cc) {
                    MessageEntity message = new MessageEntity();
                    cc.getJobEntityManager().send(message);
                    return message.getId();
                }
            };
final CommandContext cc = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration()
                                                             .getCommandContextFactory()
                                                             .createCommandContext©;

cc.getDbSqlSession().update(timer);

[indent]No errors but Job is not updated, I test with flushing and commit DbSqlSession with no more results.[/indent]



What i'm doing wrong? Or what is necessary that i not doing?

Thanks.

Outcomes