/
SubscriptionSyncJob.java
64 lines (58 loc) · 2.51 KB
/
SubscriptionSyncJob.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* Copyright Red Hat, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Red Hat trademarks are not licensed under GPLv3. No permission is
* granted to use or replicate Red Hat trademarks that are incorporated
* in this software or its documentation.
*/
package org.candlepin.subscriptions.tally.job;
import org.candlepin.subscriptions.ApplicationProperties;
import org.candlepin.subscriptions.exception.JobFailureException;
import org.candlepin.subscriptions.subscription.SubscriptionSyncController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/** A cron job to sync subscriptions to the latest upstream state for all opted-in organizations. */
@Component
@Profile("subscription-sync")
public class SubscriptionSyncJob implements Runnable {
private static final Logger log = LoggerFactory.getLogger(SubscriptionSyncJob.class);
private final SubscriptionSyncController controller;
private final ApplicationProperties applicationProperties;
@Autowired
public SubscriptionSyncJob(
SubscriptionSyncController controller, ApplicationProperties applicationProperties) {
this.controller = controller;
this.applicationProperties = applicationProperties;
}
@Override
@Scheduled(cron = "${rhsm-subscriptions.jobs.subscription-sync-schedule}")
public void run() {
if (!applicationProperties.isSubscriptionSyncEnabled()) {
log.info(
"Will not sync subscriptions for all opted-in orgs even though job was scheduled because subscriptionSyncEnabled=false.");
return;
}
try {
controller.syncAllSubscriptionsForAllOrgs();
} catch (Exception e) {
throw new JobFailureException("Failed to run " + this.getClass().getSimpleName(), e);
}
}
}