2016-07-20 16 views
0

私はRepeating Serviceからスケジュールデータを取得しています。 フォーマットをユーザーフレンドリーな方法で解析するにはどうすればよいですか? これはサンプルのスケジュール形式です。 0 13? * MON * スケジュール形式の定義方法を教えてください。スケジュールAutoScaleのデータフォーマット

ありがとうございます。

  Repeating.Service rService = Repeating.service(client, trigger.getId()); 
      Repeating repeat = rService.getObjectForRepeating(); 

      System.out.println("repeat schedule : " + repeat.getSchedule()); 

答えて

0

スケジュール属性の形式はCron形式です。

スケジュール属性:

のcron形式のスケジュール。これは、UTCタイムゾーンで実行されます。 文字列

次のJavaスクリプトあなたを助けることができる: 必須の場合は、 タイプを作成します。

/** 
* This script retrieves the Repeating trigger policies for a SoftLayer_Scale_Policy, then 
* it gets the schedule attribute and parses the value (Cron format) to human readable format. 
* 
* Important manual pages: 
* @see http://sldn.softlayer.com/reference/services/SoftLayer_Scale_Policy/getRepeatingTriggers 
* @see http://sldn.softlayer.com/reference/datatypes/SoftLayer_Scale_Policy_Trigger_Repeating 
* 
* @license <http://sldn.softlayer.com/wiki/index.php/License> 
* @author SoftLayer Technologies, Inc. <[email protected]> 
*/ 
package SoftLayer_Java_Scripts.Examples; 

import com.softlayer.api.*; 
import com.softlayer.api.service.scale.Policy; 
import com.softlayer.api.service.scale.policy.trigger.Repeating; 

import java.util.Date; 
import java.util.List; 

import org.quartz.CronExpression; 

public class GetObjectScalePolicyTriggerRepeating 
{ 
    public static void main(String[] args) 
    { 
     // Fill with your valid data here. 
     String user = "set me"; 
     String apiKey = "set me"; 

     long scalePolicyId = 1234; 

     ApiClient client = new RestApiClient().withCredentials(user, apiKey); 

     Policy.Service service = Policy.service(client, scalePolicyId); 

     try 
     { 
     List<Repeating> result = service.getRepeatingTriggers(); 
     for(Repeating rep : result) { 
      String cronValue = rep.getSchedule(); 
      System.out.println("Original value: " + cronValue); 
      // Fixing format in order to display the schedule. 
      String patch = "* " + cronValue; 
      // Using the next library: http://www.quartz-scheduler.org/api/2.2.1/org/quartz/CronExpression.html 
      CronExpression cron = new CronExpression(patch); 
      // Returns the next date/time after the given date/time which satisfies the cron expression. 
      // (i.e. the next time it's going to be triggered) 
      System.out.println("Parsed value: " + cron.getNextValidTimeAfter(new Date())); 
     } 
     } 
     catch(Exception e) 
     { 
     System.out.println("Script failed, review the next message for further details: " + e); 
     } 
    } 
} 

次のリンクはcronの形式の情報が含まれています。

http://www.nncron.ru/help/EN/working/cron-format.htm

http://www.quartz-scheduler.org/api/2.2.1/org/quartz/CronExpression.html

+0

私は間違ったデータを持っています。 <元のcron値>:0 14? * MON * :Mon Jul 25 00:14:00 KST 2016 時刻は午後2時ですが、 "cron.getNextValidTimeAfter(new Date()));" 14分を返します。それは問題ですか? –

+0

ソースコード 'String patch =" * "+ cronValue;'に次の行を追加しました。その行は結果を正確に見ることができます。それにもかかわらず、** schedule **属性はスケジューリングの目的で使用されていることを念頭に置いておく必要があります。また、私があなたに示唆しているライブラリはサードパーティライブラリなので、もっと読む必要がありますさらなる実装。 –

関連する問題