Skip to content

Commit c01a122

Browse files
authored
Merge pull request #404 from HSF/dev
Dev
2 parents 6dd6335 + 8185fa1 commit c01a122

File tree

9 files changed

+276
-76
lines changed

9 files changed

+276
-76
lines changed

atlas/setup.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,46 @@
1818
import sysconfig
1919
from setuptools import setup, find_packages
2020
from setuptools.command.install import install
21+
from wheel.bdist_wheel import bdist_wheel
2122

2223

2324
# Configure logging
2425
logging.basicConfig(level=logging.INFO)
2526
logger = logging.getLogger(__name__)
2627

2728

29+
EXCLUDED_PACKAGE = ["idds"]
30+
31+
2832
class CustomInstallCommand(install):
2933
"""Custom install command to exclude top-level 'idds' during installation."""
3034
def run(self):
3135
# Remove 'idds' from the list of packages before installation
3236
logger.info("idds-atlas installing")
3337
logger.info(f"self.distribution.packages: {self.distribution.packages}")
3438
self.distribution.packages = [
35-
pkg for pkg in self.distribution.packages if pkg != 'idds'
39+
pkg for pkg in self.distribution.packages if pkg not in EXCLUDED_PACKAGE
40+
]
41+
logger.info(f"self.distribution.packages: {self.distribution.packages}")
42+
super().run()
43+
44+
45+
class CustomBdistWheel(bdist_wheel):
46+
"""Custom wheel builder to exclude the 'idds' package but keep subpackages."""
47+
def finalize_options(self):
48+
# Exclude only the top-level 'idds', not its subpackages
49+
logger.info("idds-workflow wheel installing")
50+
logger.info(f"self.distribution.packages: {self.distribution.packages}")
51+
included_packages = [
52+
pkg for pkg in find_packages('lib/')
53+
if pkg not in EXCLUDED_PACKAGE
3654
]
55+
self.distribution.packages = included_packages
3756
logger.info(f"self.distribution.packages: {self.distribution.packages}")
57+
super().finalize_options()
58+
59+
def run(self):
60+
logger.info("CustomBdistWheel is running!") # Debug print
3861
super().run()
3962

4063

@@ -121,6 +144,7 @@ def parse_requirements(requirements_files):
121144
scripts=scripts,
122145
cmdclass={
123146
'install': CustomInstallCommand, # Exclude 'idds' during installation
147+
'bdist_wheel': CustomBdistWheel,
124148
},
125149
project_urls={
126150
'Documentation': 'https://github.com/HSF/iDDS/wiki',

client/setup.py

+26-2
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,46 @@
1818
import sysconfig
1919
from setuptools import setup, find_packages
2020
from setuptools.command.install import install
21+
from wheel.bdist_wheel import bdist_wheel
2122

2223

2324
# Configure logging
2425
logging.basicConfig(level=logging.INFO)
2526
logger = logging.getLogger(__name__)
2627

2728

29+
EXCLUDED_PACKAGE = ["idds"]
30+
31+
2832
class CustomInstallCommand(install):
2933
"""Custom install command to exclude top-level 'idds' during installation."""
3034
def run(self):
3135
# Remove 'idds' from the list of packages before installation
32-
logger.info("idds-client installing")
36+
logger.info("idds-atlas installing")
3337
logger.info(f"self.distribution.packages: {self.distribution.packages}")
3438
self.distribution.packages = [
35-
pkg for pkg in self.distribution.packages if pkg != 'idds'
39+
pkg for pkg in self.distribution.packages if pkg not in EXCLUDED_PACKAGE
40+
]
41+
logger.info(f"self.distribution.packages: {self.distribution.packages}")
42+
super().run()
43+
44+
45+
class CustomBdistWheel(bdist_wheel):
46+
"""Custom wheel builder to exclude the 'idds' package but keep subpackages."""
47+
def finalize_options(self):
48+
# Exclude only the top-level 'idds', not its subpackages
49+
logger.info("idds-workflow wheel installing")
50+
logger.info(f"self.distribution.packages: {self.distribution.packages}")
51+
included_packages = [
52+
pkg for pkg in find_packages('lib/')
53+
if pkg not in EXCLUDED_PACKAGE
3654
]
55+
self.distribution.packages = included_packages
3756
logger.info(f"self.distribution.packages: {self.distribution.packages}")
57+
super().finalize_options()
58+
59+
def run(self):
60+
logger.info("CustomBdistWheel is running!") # Debug print
3861
super().run()
3962

4063

@@ -121,6 +144,7 @@ def parse_requirements(requirements_files):
121144
scripts=scripts,
122145
cmdclass={
123146
'install': CustomInstallCommand, # Exclude 'idds' during installation
147+
'bdist_wheel': CustomBdistWheel,
124148
},
125149
project_urls={
126150
'Documentation': 'https://github.com/HSF/iDDS/wiki',

doma/setup.py

+26-2
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,46 @@
1818
import sysconfig
1919
from setuptools import setup, find_packages
2020
from setuptools.command.install import install
21+
from wheel.bdist_wheel import bdist_wheel
2122

2223

2324
# Configure logging
2425
logging.basicConfig(level=logging.INFO)
2526
logger = logging.getLogger(__name__)
2627

2728

29+
EXCLUDED_PACKAGE = ["idds"]
30+
31+
2832
class CustomInstallCommand(install):
2933
"""Custom install command to exclude top-level 'idds' during installation."""
3034
def run(self):
3135
# Remove 'idds' from the list of packages before installation
32-
logger.info("idds-client installing")
36+
logger.info("idds-atlas installing")
3337
logger.info(f"self.distribution.packages: {self.distribution.packages}")
3438
self.distribution.packages = [
35-
pkg for pkg in self.distribution.packages if pkg != 'idds'
39+
pkg for pkg in self.distribution.packages if pkg not in EXCLUDED_PACKAGE
40+
]
41+
logger.info(f"self.distribution.packages: {self.distribution.packages}")
42+
super().run()
43+
44+
45+
class CustomBdistWheel(bdist_wheel):
46+
"""Custom wheel builder to exclude the 'idds' package but keep subpackages."""
47+
def finalize_options(self):
48+
# Exclude only the top-level 'idds', not its subpackages
49+
logger.info("idds-workflow wheel installing")
50+
logger.info(f"self.distribution.packages: {self.distribution.packages}")
51+
included_packages = [
52+
pkg for pkg in find_packages('lib/')
53+
if pkg not in EXCLUDED_PACKAGE
3654
]
55+
self.distribution.packages = included_packages
3756
logger.info(f"self.distribution.packages: {self.distribution.packages}")
57+
super().finalize_options()
58+
59+
def run(self):
60+
logger.info("CustomBdistWheel is running!") # Debug print
3861
super().run()
3962

4063

@@ -121,6 +144,7 @@ def parse_requirements(requirements_files):
121144
scripts=scripts,
122145
cmdclass={
123146
'install': CustomInstallCommand, # Exclude 'idds' during installation
147+
'bdist_wheel': CustomBdistWheel,
124148
},
125149
project_urls={
126150
'Documentation': 'https://github.com/HSF/iDDS/wiki',

main/lib/idds/agents/coordinator/coordinator.py

+90-58
Original file line numberDiff line numberDiff line change
@@ -224,83 +224,115 @@ def insert_event(self, event):
224224

225225
def send(self, event):
226226
with self._lock:
227-
self.insert_event(event)
227+
try:
228+
self.insert_event(event)
229+
except Exception as ex:
230+
self.logger.error(f"Failed to send event: {ex}")
231+
self.logger.error(traceback.format_exc())
228232

229233
def send_bulk(self, events):
230234
with self._lock:
231235
for event in events:
232-
self.insert_event(event)
236+
try:
237+
self.insert_event(event)
238+
except Exception as ex:
239+
self.logger.error(f"Failed to send event: {ex}")
240+
self.logger.error(traceback.format_exc())
233241

234242
def get(self, event_type, num_events=1, wait=0):
235243
with self._lock:
236244
events = []
237245
for i in range(num_events):
238-
if event_type in self.events_index:
239-
for scheduled_priority in [EventPriority.High, EventPriority.Medium, EventPriority.Low]:
240-
if (scheduled_priority in self.events_index[event_type] and self.events_index[event_type][scheduled_priority]):
241-
event_id = self.events_index[event_type][scheduled_priority][0]
242-
event = self.events[event_id]
243-
if event.scheduled_time <= time.time():
244-
event_id = self.events_index[event_type][scheduled_priority].pop(0)
245-
event = self.events[event_id]
246-
del self.events[event_id]
247-
self.events_ids[event.get_event_id()].remove(event_id)
248-
249-
if event._event_type in self.accounts:
250-
self.accounts[event._event_type]['total_queued_events'] -= 1
251-
self.accounts[event._event_type]['total_processed_events'] += 1
252-
253-
self.logger.debug("Get event %s" % (event.to_json(strip=True)))
254-
events.append(event)
246+
try:
247+
if event_type in self.events_index:
248+
for scheduled_priority in [EventPriority.High, EventPriority.Medium, EventPriority.Low]:
249+
if (scheduled_priority in self.events_index[event_type] and self.events_index[event_type][scheduled_priority]):
250+
event_id = self.events_index[event_type][scheduled_priority][0]
251+
if event_id not in self.events:
252+
self.events_index[event_type][scheduled_priority].pop(0)
253+
else:
254+
event = self.events[event_id]
255+
if event.scheduled_time <= time.time():
256+
event_id = self.events_index[event_type][scheduled_priority].pop(0)
257+
event = self.events[event_id]
258+
del self.events[event_id]
259+
self.events_ids[event.get_event_id()].remove(event_id)
260+
261+
if event._event_type in self.accounts:
262+
self.accounts[event._event_type]['total_queued_events'] -= 1
263+
self.accounts[event._event_type]['total_processed_events'] += 1
264+
265+
self.logger.debug("Get event %s" % (event.to_json(strip=True)))
266+
events.append(event)
267+
except Exception as ex:
268+
self.logger.error(f"Failed to send event: {ex}")
269+
self.logger.error(traceback.format_exc())
255270

256271
if not events:
257-
if event_type in self.accounts:
258-
if self.accounts[event_type]['total_queued_events'] == 0:
259-
self.accounts[event_type]['lack_events'] = True
272+
try:
273+
if event_type in self.accounts:
274+
if self.accounts[event_type]['total_queued_events'] == 0:
275+
self.accounts[event_type]['lack_events'] = True
276+
except Exception as ex:
277+
self.logger.error(f"Failed to send event: {ex}")
278+
self.logger.error(traceback.format_exc())
279+
260280
return events
261281

262282
def send_report(self, event, status, start_time, end_time, source, result):
263-
event_id = event.get_event_id()
264-
event_ret_status = status
265-
event_name = event._event_type.name
266-
if not event_ret_status and result:
267-
event_ret_status = result.get("status", None)
268-
if event_id not in self.report:
269-
self.report[event_id] = {"status": event_ret_status,
270-
"total_files": None,
271-
"processed_files": None,
272-
"event_types": {}}
273-
self.report[event_id]['status'] = event_ret_status
274-
self.report[event_id]['event_types'][event_name] = {'start_time': start_time,
275-
'end_time': end_time,
276-
'source': source,
277-
'status': event_ret_status,
278-
'result': result}
283+
try:
284+
event_id = event.get_event_id()
285+
event_ret_status = status
286+
event_name = event._event_type.name
287+
if not event_ret_status and result:
288+
event_ret_status = result.get("status", None)
289+
if event_id not in self.report:
290+
self.report[event_id] = {"status": event_ret_status,
291+
"total_files": None,
292+
"processed_files": None,
293+
"event_types": {}}
294+
self.report[event_id]['status'] = event_ret_status
295+
self.report[event_id]['event_types'][event_name] = {'start_time': start_time,
296+
'end_time': end_time,
297+
'source': source,
298+
'status': event_ret_status,
299+
'result': result}
300+
except Exception as ex:
301+
self.logger.error(f"Failed to send event: {ex}")
302+
self.logger.error(traceback.format_exc())
279303

280304
def clean_cache_info(self):
281305
with self._lock:
282-
event_ids = list(self.events_ids.keys())
283-
for event_id in event_ids:
284-
if not self.events_ids[event_id]:
285-
del self.events_ids[event_id]
286-
287-
event_ids = list(self.report.keys())
288-
for event_id in event_ids:
289-
event_types = list(self.report[event_id]['event_types'].keys())
290-
for event_type in event_types:
291-
end_time = self.report[event_id]['event_types'][event_type].get('end_time', None)
292-
if not end_time or end_time < time.time() - 86400 * 10:
293-
del self.report[event_id]['event_types'][event_type]
294-
if not self.report[event_id]['event_types']:
295-
del self.report[event_id]
306+
try:
307+
event_ids = list(self.events_ids.keys())
308+
for event_id in event_ids:
309+
if not self.events_ids[event_id]:
310+
del self.events_ids[event_id]
311+
312+
event_ids = list(self.report.keys())
313+
for event_id in event_ids:
314+
event_types = list(self.report[event_id]['event_types'].keys())
315+
for event_type in event_types:
316+
end_time = self.report[event_id]['event_types'][event_type].get('end_time', None)
317+
if not end_time or end_time < time.time() - 86400 * 10:
318+
del self.report[event_id]['event_types'][event_type]
319+
if not self.report[event_id]['event_types']:
320+
del self.report[event_id]
321+
except Exception as ex:
322+
self.logger.error(f"Failed to send event: {ex}")
323+
self.logger.error(traceback.format_exc())
296324

297325
def show_queued_events(self):
298-
if self.show_queued_events_time is None or self.show_queued_events_time + self.show_queued_events_time_interval < time.time():
299-
self.show_queued_events_time = time.time()
300-
for event_type in self.events_index:
301-
self.logger.info("Number of events has processed: %s: %s" % (event_type.name, self.accounts.get(event_type, {}).get('total_processed_events', None)))
302-
for prio in self.events_index[event_type]:
303-
self.logger.info("Number of queued events: %s %s: %s" % (event_type.name, prio.name, len(self.events_index[event_type][prio])))
326+
try:
327+
if self.show_queued_events_time is None or self.show_queued_events_time + self.show_queued_events_time_interval < time.time():
328+
self.show_queued_events_time = time.time()
329+
for event_type in self.events_index:
330+
self.logger.info("Number of events has processed: %s: %s" % (event_type.name, self.accounts.get(event_type, {}).get('total_processed_events', None)))
331+
for prio in self.events_index[event_type]:
332+
self.logger.info("Number of queued events: %s %s: %s" % (event_type.name, prio.name, len(self.events_index[event_type][prio])))
333+
except Exception as ex:
334+
self.logger.error(f"Failed to send event: {ex}")
335+
self.logger.error(traceback.format_exc())
304336

305337
def coordinate(self):
306338
self.select_coordinator()

0 commit comments

Comments
 (0)