embulk-input-facebook_ads_insights 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e75615b6132e2b71944d55f536a292910f751152
4
- data.tar.gz: 4f7b3a10f5b5e0ea05cf61530a25fbbb72a7d31c
3
+ metadata.gz: e15001bc050404e05fc3b7e722b04c0a5482d99e
4
+ data.tar.gz: f7ab80fcb6b69af1af7c4b1d89d89962bce2aabb
5
5
  SHA512:
6
- metadata.gz: b68579162e9d20d377231ca22ab6e046b39751442d68d91c06aa04141cdb9a5d8ca34712b59c1c64aeddd36d6e80caea26b3958c34d781a1884436350eaccacd
7
- data.tar.gz: 2464a3b4d078e8b170400655523023716da68efdb0108947e5613b8a2a2dd626ea66ae89a51c4f5d08cc6e46d4b37c6875e0cc39b4d2d5aa144e4d623d3c01ef
6
+ metadata.gz: 1ec4d35fec9a2004948a407fa3b26265b3519167be8fd03306c74ace9ed617cb13d969ace589d291aa9dba923661a94db24fba6b18a051970f8ceffd7ccd58a6
7
+ data.tar.gz: 336ade308d51f06878cbd228ba39a1de3c85fc65fc98c23de86ccd8a49c984d633d73e9a09bf81209ca711586cb2f30635792e00ba30f2f4070be7fce4f0ee17
data/README.md CHANGED
@@ -19,7 +19,7 @@ Required Embulk version >= 0.9
19
19
  | object_type | yes | ObjectEnum | ads object type. |
20
20
  | object_id | yes | string | ads object id. |
21
21
  | fields | yes | array({name:{FieldEnum, BreakdownEnum}, type:string}) | columns to fetch. |
22
- | action_attribution_windows | no | array(ActionAttributionWindowEnum) | see [action_attribution_windows](https://developers.facebook.com/docs/marketing-api/insights/parameters) for details. |
22
+ | action_attribution_windows | no | array(ActionAttributionWindowEnum) | see [action_attribution_windows](https://developers.facebook.com/docs/marketing-api/insights/parameters) for details. |
23
23
  | action_breakdowns | no | array(ActionBreakdownEnum) | see [action_breakdowns](https://developers.facebook.com/docs/marketing-api/insights/parameters) for details. |
24
24
  | action_report_time | no | enum{impression, conversion} | see [action_report_time](https://developers.facebook.com/docs/marketing-api/insights/parameters) for details. |
25
25
  | breakdowns | no | array(BreakdownEnum) | see [breakdowns](https://developers.facebook.com/docs/marketing-api/insights/parameters) for details. |
data/build.gradle CHANGED
@@ -13,7 +13,7 @@ configurations {
13
13
  provided
14
14
  }
15
15
 
16
- version = "0.1.9"
16
+ version = "0.1.10"
17
17
 
18
18
  sourceCompatibility = 1.8
19
19
  targetCompatibility = 1.8
@@ -24,7 +24,8 @@ import java.util.stream.Collectors;
24
24
  public class Client
25
25
  {
26
26
  private final Logger logger = LoggerFactory.getLogger(Client.class);
27
- private static final int ASYNC_SLEEP_TIME = 3000;
27
+ private static final int ASYNC_SLEEP_TIME = 30000;
28
+ private static final int ASYNC_SLEEP_TIME_LIMIT = 900_000;
28
29
 
29
30
  private final PluginTask pluginTask;
30
31
 
@@ -35,44 +36,68 @@ public class Client
35
36
 
36
37
  public List<AdsInsights> getInsights(boolean isPaginationValid) throws APIException, InterruptedException
37
38
  {
38
- AdReportRun adReportRun;
39
- switch (pluginTask.getObjectType()) {
40
- case ACCOUNT: {
41
- adReportRun = getAdAccountInsights();
42
- break;
39
+ int elapsedTime = 0;
40
+ boolean asyncCompleted = false;
41
+ AdReportRun adReportRun = null;
42
+ while (!asyncCompleted) {
43
+ switch (pluginTask.getObjectType()) {
44
+ case ACCOUNT: {
45
+ adReportRun = getAdAccountInsights();
46
+ break;
47
+ }
48
+ case CAMPAIGN: {
49
+ adReportRun = getCampaignInsights();
50
+ break;
51
+ }
52
+ case ADSET: {
53
+ adReportRun = getAdSetInsights();
54
+ break;
55
+ }
56
+ case AD: {
57
+ adReportRun = getAdInsights();
58
+ break;
59
+ }
60
+ default: throw new IllegalArgumentException();
43
61
  }
44
- case CAMPAIGN: {
45
- adReportRun = getCampaignInsights();
46
- break;
47
- }
48
- case ADSET: {
49
- adReportRun = getAdSetInsights();
50
- break;
51
- }
52
- case AD: {
53
- adReportRun = getAdInsights();
54
- break;
55
- }
56
- default: throw new IllegalArgumentException();
57
- }
58
- logger.info(adReportRun.getRawResponse());
59
- int asyncLoopCount = 0;
60
- while (adReportRun.fetch().getFieldAsyncPercentCompletion() != 100) {
61
62
  logger.info(adReportRun.getRawResponse());
62
- Thread.sleep(ASYNC_SLEEP_TIME);
63
- if (adReportRun.getFieldAsyncStatus().equals("Job Skipped")) {
64
- throw new RuntimeException("async was aborted because the AsyncStatus is \"Job Skipped\"");
63
+
64
+ String jobStatus = "";
65
+ try {
66
+ while (adReportRun.fetch().getFieldAsyncPercentCompletion() != 100) {
67
+ logger.info(adReportRun.getRawResponse());
68
+ Thread.sleep(ASYNC_SLEEP_TIME);
69
+ elapsedTime += ASYNC_SLEEP_TIME;
70
+ if (adReportRun.getFieldAsyncStatus().equals("Job Skipped")) {
71
+ jobStatus = "skipped";
72
+ throw new RuntimeException("async was aborted because the AsyncStatus is \"Job Skipped\"");
73
+ }
74
+ if (adReportRun.getFieldAsyncStatus().equals("Job Failed")) {
75
+ jobStatus = "failed";
76
+ throw new RuntimeException("async was aborted because the AsyncStatus is \"Job Failed\"");
77
+ }
78
+ if (adReportRun.getFieldAsyncStatus().equals("Job Not Started") && elapsedTime >= ASYNC_SLEEP_TIME_LIMIT) {
79
+ jobStatus = "aborted";
80
+ throw new RuntimeException("async was aborted because the number of retries exceeded the limit");
81
+ }
82
+ }
83
+ asyncCompleted = true;
65
84
  }
66
- if (++asyncLoopCount >= 300) {
67
- throw new RuntimeException("async was aborted because the number of retries exceeded the limit");
85
+ catch (RuntimeException e) {
86
+ if (jobStatus != "failed"){
87
+ throw new APIException(e);
88
+ }
68
89
  }
69
90
  }
91
+ if (adReportRun == null || adReportRun.getFieldAsyncPercentCompletion() != 100) {
92
+ throw new APIException();
93
+ }
70
94
  logger.info(adReportRun.getRawResponse());
95
+
71
96
  // extra waiting
72
97
  int retryCount = 0;
73
98
  boolean succeeded = false;
74
99
  APINodeList<AdsInsights> adsInsights = null;
75
- while (retryCount < pluginTask.getMaxWeightSeconds() && !succeeded) {
100
+ while (retryCount < pluginTask.getMaxWaitSeconds() && !succeeded) {
76
101
  try {
77
102
  Thread.sleep(1000);
78
103
  adsInsights = adReportRun.getInsights().execute();
@@ -84,5 +84,5 @@ public interface PluginTask extends Task
84
84
 
85
85
  @Config("max_wait_seconds")
86
86
  @ConfigDefault("60")
87
- public Integer getMaxWeightSeconds();
87
+ public Integer getMaxWaitSeconds();
88
88
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-input-facebook_ads_insights
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - naotaka nakane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-26 00:00:00.000000000 Z
11
+ date: 2021-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -52,7 +52,7 @@ files:
52
52
  - classpath/annotations-13.0.jar
53
53
  - classpath/byte-buddy-1.10.13.jar
54
54
  - classpath/byte-buddy-agent-1.10.13.jar
55
- - classpath/embulk-input-facebook_ads_insights-0.1.9.jar
55
+ - classpath/embulk-input-facebook_ads_insights-0.1.10.jar
56
56
  - classpath/facebook-java-business-sdk-10.0.0.jar
57
57
  - classpath/gson-2.5.jar
58
58
  - classpath/guava-20.0.jar