API using the same code as Job Scheduler doens't create/update content

Alex Camaroti, modified 6 Years ago. New Member Posts: 16 Join Date: 4/8/19 Recent Posts
Hello guys,

  My situation is:

  I have a scheduled job already that create/update around 1 thousand of contents. The total processing time is 5 hours.

Job calling method:
    @Override
    protected void doReceive(Message message) throws Exception {
        try {
            ImportContent.getInstace().init();
        } catch (Exception e) {
            e.printStackTrace();
        }
        registerScheduler();
    }

My method is like:
private void init() {
//a lot of rules
 JournalArticleLocalServiceUtil.updateJournalArticle(article);
}
​​​​​​​
I did an api that I access on api/jsonws that calls the same method.
and when it is running, all the logs run, but the content itself doenst update/create (depending of the rule). 
    public String callImportContentByJob(){
        try {
            ImportContent.getInstace().init();
        } catch (PortalException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
        return "The execution is finished.";
    }
​​​​​​​My question is: what should I do in this case. Does it has some problem If my api spend more than a specific time?
I dont have idea what's happening as I'm using the same code.
Alex Camaroti, modified 6 Years ago. New Member Posts: 16 Join Date: 4/8/19 Recent Posts
I also saw that the contents only update when the service finishes its processing.
thumbnail
Amos Fong, modified 6 Years ago. Liferay Legend Posts: 2047 Join Date: 10/7/08 Recent Posts
Where are you seeing it not update? is it updated in the DB?

Maybe your entire method is under one transaction?

Maybe you should call the other service method because it does other things like updates the AssetEntry and reindexes:
@Indexable(type = IndexableType.REINDEX)
@Override
public JournalArticle updateArticle(
      long userId, long groupId, long folderId, String articleId,
      double version, Map<locale, string> titleMap,
      Map<locale, string> descriptionMap, String content,
      String ddmStructureKey, String ddmTemplateKey, String layoutUuid,
      int displayDateMonth, int displayDateDay, int displayDateYear,
      int displayDateHour, int displayDateMinute, int expirationDateMonth,
      int expirationDateDay, int expirationDateYear,
      int expirationDateHour, int expirationDateMinute,
      boolean neverExpire, int reviewDateMonth, int reviewDateDay,
      int reviewDateYear, int reviewDateHour, int reviewDateMinute,
      boolean neverReview, boolean indexable, boolean smallImage,
      String smallImageURL, File smallImageFile,
      Map<string, byte[]> images, String articleURL,
      ServiceContext serviceContext)
   throws PortalException {</string,></locale,></locale,>