Skip to content

Commit 89a178d

Browse files
authored
Merge pull request #10 from mlibrary/updating-digifeeds-updater
searches first for the set id
2 parents e60c163 + 79f2d03 commit 89a178d

File tree

5 files changed

+109
-7
lines changed

5 files changed

+109
-7
lines changed

env.example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ ALMA_API_HOST='https://api-na.hosted.exlibrisgroup.com'
77
STUDENT_USERS_SET_ID="your_users_set_id"
88

99
# hathitrust
10-
DIGIFEEDS_SET_ID="some_set_id"
1110
CHANGE_PHYSICAL_ITEM_INFORMATION_JOB_ID="some_job_id"
1211

1312
# sms

lib/aim/cli.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ class HathiTrust < Thor
1212
that Umich is the digitizer of the item.
1313
DESC
1414
def set_digitizer
15+
start_time = Time.now.to_i
16+
AIM::HathiTrust::DigitizerSetter.configure
1517
AIM::HathiTrust::DigitizerSetter.new.run
18+
AIM::HathiTrust::DigitizerSetter.send_metrics(start_time)
1619
end
1720
end
1821

lib/aim/hathi_trust/digitizer_setter.rb

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,43 @@
11
module AIM
22
module HathiTrust
33
class DigitizerSetter
4+
def self.configure
5+
::Yabeda.configure do
6+
gauge :aim_hathi_trust_set_digitizer_last_success, comment: "Start time of the last Set Digitizer Job that successfully finished."
7+
end
8+
Yabeda.configure!
9+
end
10+
11+
def self.send_metrics(start_time)
12+
Yabeda.aim_hathi_trust_set_digitizer_last_success.set({}, start_time)
13+
begin
14+
Yabeda::Prometheus.push_gateway.add(Yabeda::Prometheus.registry)
15+
rescue
16+
Logger.new($stdout).error("Failed to contact the push gateway")
17+
end
18+
end
19+
420
def initialize(logger: Logger.new($stdout))
521
@logger = logger
622
end
723

824
def run
25+
@logger.info("Fetching digifeeds_metadata set id")
26+
sets_resp = AlmaRestClient.client.get_all(url: "/conf/sets", record_key: "set", query: {"q" => "name~digifeeds_metadata"})
27+
if sets_resp.status != 200
28+
@logger.error("Failed to fetch set")
29+
abort
30+
end
31+
32+
set_id = sets_resp
33+
.body["set"]
34+
.filter_map { |x| x["id"] if x["name"] == "digifeeds_metadata" }
35+
.first
36+
37+
@logger.info("Set Id: #{set_id}")
38+
939
@logger.info("Sending Change Physical Item Job to set the Digitizer to Umich for Digifeeds")
10-
resp = AlmaRestClient.client.post("/conf/jobs/#{ENV.fetch("CHANGE_PHYSICAL_ITEM_INFORMATION_JOB_ID")}?op=run", body: body)
40+
resp = AlmaRestClient.client.post("/conf/jobs/#{ENV.fetch("CHANGE_PHYSICAL_ITEM_INFORMATION_JOB_ID")}?op=run", body: body(set_id: set_id))
1141
@logger.info resp.body
1242
if resp.status == 200
1343
@logger.info("Finished Sending Change Physical Items job")
@@ -16,9 +46,9 @@ def run
1646
end
1747
end
1848

19-
def body
49+
def body(set_id:)
2050
{
21-
"parameter" => params.map do |name, value|
51+
"parameter" => params(set_id: set_id).map do |name, value|
2252
{
2353
"name" => {"value" => name, "desc" => name},
2454
"value" => value
@@ -27,11 +57,11 @@ def body
2757
}
2858
end
2959

30-
def params
60+
def params(set_id:)
3161
{
3262
"STATISTICS_NOTE_1_value" => digitizer,
3363
"STATISTICS_NOTE_1_selected" => true,
34-
"set_id" => ENV.fetch("DIGIFEEDS_SET_ID"),
64+
"set_id" => set_id,
3565
"job_name" => job_name
3666
}
3767
end

spec/aim/hathi_trust/digitizer_setter_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
[
77
{"name" => {"value" => "STATISTICS_NOTE_1_value", "desc" => "STATISTICS_NOTE_1_value"}, "value" => "umich"},
88
{"name" => {"value" => "STATISTICS_NOTE_1_selected", "desc" => "STATISTICS_NOTE_1_selected"}, "value" => true},
9-
{"name" => {"value" => "set_id", "desc" => "set_id"}, "value" => ENV.fetch("DIGIFEEDS_SET_ID")},
9+
{"name" => {"value" => "set_id", "desc" => "set_id"}, "value" => "999"},
1010
{"name" => {"value" => "job_name", "desc" => "job_name"}, "value" => "Change Physical items information - set digitizer to Umich"}
1111
]}
1212

13+
stub_alma_get_request(url: "conf/sets?q=name~digifeeds_metadata&limit=100&offset=0", output: fixture("hathi_trust/digitizer_setter_sets.json"))
1314
request = stub_alma_post_request(url: "conf/jobs/#{ENV.fetch("CHANGE_PHYSICAL_ITEM_INFORMATION_JOB_ID")}?op=run", input: body)
1415
described_class.new(logger: logger_double).run
1516
expect(request).to have_been_requested
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"set": [
3+
{
4+
"id": "111",
5+
"name": "digifeeds_metadata_20230607",
6+
"description": "three missing volumes from 20230504",
7+
"type": {
8+
"value": "ITEMIZED",
9+
"desc": "Itemized"
10+
},
11+
"content": {
12+
"value": "ITEM",
13+
"desc": "Physical items"
14+
},
15+
"status": {
16+
"value": "ACTIVE",
17+
"desc": "Active"
18+
},
19+
"origin": {
20+
"value": "UI",
21+
"desc": "Institution only"
22+
},
23+
"private": {
24+
"value": "false",
25+
"desc": "No"
26+
},
27+
"status_date": "2023-06-07T19:00:32.689Z",
28+
"created_by": {
29+
"value": "test",
30+
"desc": "TEST, TEST"
31+
},
32+
"created_date": "2023-06-07T19:00:32.689Z",
33+
"link": "https://api-na.hosted.exlibrisgroup.com/almaws/v1/conf/sets/111"
34+
},
35+
{
36+
"id": "999",
37+
"name": "digifeeds_metadata",
38+
"description": "list of metadata for digifeeds",
39+
"type": {
40+
"value": "ITEMIZED",
41+
"desc": "Itemized"
42+
},
43+
"content": {
44+
"value": "ITEM",
45+
"desc": "Physical items"
46+
},
47+
"status": {
48+
"value": "ACTIVE",
49+
"desc": "Active"
50+
},
51+
"origin": {
52+
"value": "UI",
53+
"desc": "Institution only"
54+
},
55+
"private": {
56+
"value": "false",
57+
"desc": "No"
58+
},
59+
"status_date": "2023-07-17T17:23:03.086Z",
60+
"created_by": {
61+
"value": "test",
62+
"desc": "TEST, TEST"
63+
},
64+
"created_date": "2023-07-17T17:23:03.086Z",
65+
"link": "https://api-na.hosted.exlibrisgroup.com/almaws/v1/conf/sets/999"
66+
}
67+
],
68+
"total_record_count": 2
69+
}

0 commit comments

Comments
 (0)